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
    
    
  • 相关阅读:
    友盟页面统计
    为什么调用 FragmentPagerAdapter.notifyDataSetChanged() 并不能更新其 Fragment?
    让jQuery的ajaxFileUpload插件支持onchange事件
    sublime双击选择全选带中划线
    配置Chrome Workspace功能
    font-face 跨域解决
    Yahoo团队经验:网站性能优化的34条黄金法则
    require.js+knockout.js+.underscore模板引擎的使用
    使用livereload实现自动刷新
    WebStorm 7.0 支持更多的Web技术
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12215650.html
Copyright © 2011-2022 走看看