Poj 3090 Visible Lattice Points(欧拉函数)

来源:互联网 发布:学习c语言编程 编辑:程序博客网 时间:2024/05/18 02:29

Language:
Visible Lattice Points
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5797 Accepted: 3424

Description

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

4245231

Sample Output

1 2 52 4 133 5 214 231 32549


从点(0,0)到(x,y)不经过其他点  及x,y互素

问题 就变为求1到n内互素的数的对数 因为是对称的需要乘以2  另外还要加上(0,1)这个点

#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 1010#define MAXM 100010#define INF 99999999#define ll __int64#define bug cout<<"here"<<endl#define fread freopen("ceshi.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;int Read(){    char ch;    int a = 0;    while((ch = getchar()) == ' ' | ch == '\n');    a += ch - '0';    while((ch = getchar()) != ' ' && ch != '\n')    {        a *= 10;        a += ch - '0';    }    return a;}void Print(int a)    //输出外挂{     if(a>9)         Print(a/10);     putchar(a%10+'0');}int phi[MAXN];void init(){    for(int i=1;i<MAXN;i++) phi[i]=i;    for(int i=2;i<MAXN;i+=2) phi[i]/=2;    for(int i=3;i<MAXN;i+=2)        if(phi[i]==i)        {            for(int j=i;j<MAXN;j+=i)                phi[j]=phi[j]/i*(i-1);        }    for(int i=2;i<MAXN;i++)        phi[i]+=phi[i-1];}int main(){    //fread;    int tc;    scanf("%d",&tc);    int cs=1;    init();    while(tc--)    {        int n;        scanf("%d",&n);        printf("%d %d %d\n",cs++,n,phi[n]*2+1);    }    return 0;}





0 0
原创粉丝点击