zoukankan      html  css  js  c++  java
  • POJ 3090

    Visible Lattice Points
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 8397   Accepted: 5144

    Description

    A lattice point (x, y) 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 (x, y) 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 (x, y) with 0 ≤ x, y ≤ 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 (x, y) with 0 ≤ x, yN.

    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

    Source

    [Submit]   [Go Back]   [Status]   [Discuss]

    刚开始脑子简单去暴力循环。。当然是T掉啦!

    原来一直不明白欧拉函数,f(n)代表小于n的正整数中与n互质的数的数目。。就是这个题嘛。。记住了。

     

     1 #include <cstdlib>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <algorithm>
     5 #include<iostream>
     6 #include <cmath>
     7 #include<string>
     8 #define ll long long 
     9 #define dscan(a) scanf("%d",&a)
    10 #define mem(a,b) memset(a,b,sizeof a)
    11 using namespace std;
    12 #define MAXL 1105
    13 #define maxn 1000005
    14 int f[MAXL];
    15 inline int read()
    16 {
    17     int x=0,f=1;char ch=getchar();
    18     while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    19     while(ch>='0'&&ch<='9') {x=10*x+ch-'0';ch=getchar();}
    20     return x*f;
    21 }
    22 int p[MAXL], pNum, phi[MAXL];
    23 void ola()
    24 {
    25     int i, j;
    26     for(i = 2; i < MAXL; i++) {
    27         if(!f[i]) { p[pNum++] = i; phi[i] = i-1;}
    28         for(j = 0; j < pNum && p[j] * i < MAXL; j++ ) {
    29             f[p[j]*i] = 1;
    30             if(i % p[j] == 0){
    31                 phi[i*p[j]] = phi[i] * p[j];
    32                 break;
    33             }
    34             else phi[i*p[j]] = phi[i] *(p[j] - 1);
    35         }
    36     }
    37 }
    38 int main()
    39 {
    40     int n,c;
    41     cin>>n;int hh=1;
    42     ola();
    43     while(n--)
    44     {
    45         int c=read();
    46         phi[1]=1;
    47         cout<<hh++<<" "<<c<<" ";
    48         ll ans=0;
    49         for(int i=1;i<=c;++i) ans+=phi[i];
    50         cout<<ans*2+1<<endl;
    51     }
    52 }
    View Code

     

     

     

  • 相关阅读:
    webmagic的使用学习
    redis在macOS上的安装及与springboot的整合使用
    Swagger-UI
    个人作业——软件工程实践总结&个人技术博客
    祝贺大野鸡喜提小黄衫一件
    软件评测(个人作业)
    结对第二次作业
    Springboot项目创建文件中相对路径问题
    二进制翻转
    欧拉降幂及广义欧拉降幂证明
  • 原文地址:https://www.cnblogs.com/TYH-TYH/p/9378127.html
Copyright © 2011-2022 走看看