zoukankan      html  css  js  c++  java
  • Day7

    A lattice point (xy) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (xy) does not pass through any other lattice point. For example, the point (4, 2) is not visible since the line from the origin passes through (2, 1). The figure below shows the points (xy) with 0 ≤ xy ≤ 5 with lines from the origin to the visible points.

    Write a program which, given a value for the size, N, computes the number of visible points (xy) with 0 ≤ xy ≤ N.

    Input

    The first line of input contains a single integer C (1 ≤ C ≤ 1000) which is the number of datasets that follow.

    Each dataset consists of a single line of input containing a single integer N (1 ≤ N ≤ 1000), which is the size.

    Output

    For each dataset, there is to be one line of output consisting of: the dataset number starting at 1, a single space, the size, a single space and the number of visible points for that size.

    Sample Input

    4
    2
    4
    5
    231

    Sample Output

    1 2 5
    2 4 13
    3 5 21
    4 231 32549

    思路:裸的欧拉函数,相当于求在第一象限有多少个不同斜率的点,k=y/x,当y与x互质时,其值唯一,直接打表求欧拉函数前缀和就行,y,x不同所以要乘2,y,x相同时未算,所以要加1
    const int maxm = 1005;
    
    int Euler[maxm];
    
    void get_Euler() {
        Euler[1] = 1;
        for(int i = 2; i <= maxm; ++i) {
            if(!Euler[i]) {
                for(int j = i; j <= maxm; j += i) {
                    if(!Euler[j]) Euler[j] = j;
                    Euler[j] = Euler[j] / i * (i-1);
                }
            }
        }
    }
    
    int main() {
        get_Euler();
        for(int i = 1; i <= maxm; ++i)
            Euler[i] += Euler[i-1];
        int T, N;
        scanf("%d", &T);
        for(int i = 1; i <= T; ++i) {
            scanf("%d", &N);
            printf("%d %d %d
    ", i, N, 2 * Euler[N] + 1);
        }
        return 0;
    }
    View Code
    
    
  • 相关阅读:
    第五周学习总结-20175218
    第一周测试总结分析
    第四周学习总结-20175218
    第三周学习总结-20175218
    第二周学习任务-20175218
    第一周学习总结-20175218
    20175213 2018-2019-2 《Java程序设计》第11周学习总结
    数据结构-排序(选做)
    20175213 2018-2019-2 《Java程序设计》第10周学习总结
    2018-2019-2 20175213实验三《敏捷开发与XP实践》实验报告
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12215650.html
Copyright © 2011-2022 走看看