POJ 3090 Visible Lattice Points

来源:互联网 发布:陕西广电网络宽带电话 编辑:程序博客网 时间:2024/03/29 18:10
Visible Lattice Points
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5012 Accepted: 2910

Description

A lattice point (x, y) in the first quadrant (x andy 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

4245231

Sample Output

1 2 52 4 133 5 214 231 32549

Source

Greater New York 2006

 

【题目大意】:

          从原点看第一象限里的所有点,能直接看到的点的数目是多少。(不包含原点)

【分析】:

          与这道题很像,详情点击:http://blog.csdn.net/csyzcyj/article/details/17332211<BZOJ 2190 [SDOI2008]仪仗队 题解 >

【代码】:

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<iostream>#include<vector>#include<stack>#include<queue>using namespace std;#define MAXN 1001int C,ans[MAXN],p[MAXN];bool a[MAXN];void euler(){      int num=0;      for(int i=2;i<=1000;i++)      {            if(!a[i])            {                  p[num++]=i;                  ans[i]=i-1;            }            for(int j=0;j<num&&p[j]*i<=1000;j++)            {                  a[p[j]*i]=true;                  if(!(i%p[j]))                  {                        ans[i*p[j]]=ans[i]*p[j];                        break;                     }                  else  ans[i*p[j]]=ans[i]*(p[j]-1);            }      }}int main(){      //freopen("input.in","r",stdin);  //freopen("output.out","w",stdout);   scanf("%d",&C);  euler();  for(int i=1;i<=C;i++)  {            int N;            long long ans1=1;            scanf("%d",&N);            for(int j=2;j<=N;j++)                  ans1+=ans[j];            printf("%d %d %lld\n",i,N,2*ans1+1);      }  //system("pause");      return 0;}


 

转载注明出处:http://blog.csdn.net/u011400953

 

0 0
原创粉丝点击