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
    
    
  • 相关阅读:
    机器学习之--画图补充
    机器学习之--KNN算法简单实现
    redhat centos yum源的安装
    redhat6.5 linux 安装mysql5.6.27
    bash 截取字符串
    redhat vim编辑器永久添加行号及搜索
    Orthomcl的详细使用
    InterProScan 5.25-64.0 安装和使用
    paml正选择处理时序列里有终止密码子怎么处理掉
    R语言putty中直接使用X11(Xming)绘图
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12215650.html
Copyright © 2011-2022 走看看