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
    
    
  • 相关阅读:
    网络流24题-分配问题
    网络流24题-圆桌问题
    git ssh
    SQL Server 添加说明 语句
    问题思路
    数据库事务和锁
    Castle Windsor
    Flask学习笔记11之特殊的装饰器
    python中的"环绕通知"
    Flask学习笔记10之flash
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12215650.html
Copyright © 2011-2022 走看看