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
    
    
  • 相关阅读:
    JS魔法堂:阻止元素被选中
    JS魔法堂之实战:纯前端的图片预览
    CentOS6.5菜鸟之旅:纯转载Linux目录结构
    Vim杂记:Sublime的配色方案
    Vim杂记:markdown插件
    CentOS6.5菜鸟之旅:中文编辑器忍痛放弃Sublime
    JS魔法堂:Data URI Scheme介绍
    CentOS6.5菜鸟之旅:安装ATI显卡驱动
    JS魔法堂:获取当前脚本文件的绝对路径
    腊八蒜
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12215650.html
Copyright © 2011-2022 走看看