【POJ】3090 Visible Lattice Points(欧拉函数)

Visible Lattice Points
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7705   Accepted: 4707

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.

【POJ】3090 Visible Lattice 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
----------------------------------------------------------------- 分析:和[SDOI2008]仪仗队没有什么区别,只是加了个多数据。
[SDOI2008]仪仗队 -》 http://www.cnblogs.com/noblex/p/7535245.html
还是放一下代码吧
 #include <cstdio>
#include <cmath>
const int maxn=;
int phi[maxn];
int phis(int n)
{
for(int i=;i<=n;i++) phi[i]=;
for(int i=;i<=n;i++)
{
if(!phi[i])
for(int j=i;j<=n;j+=i)
{
if(!phi[j]) phi[j]=j;
phi[j]=phi[j]/i*(i-);
}
}
return ;
}
int main()
{
int t,n;
scanf("%d",&t);
phis(maxn);
for(int i=;i<=t;i++)
{
long long sum=;
scanf("%d",&n);
for(int j=;j<=n;j++) sum+=phi[j];
sum*=;sum+=;
printf("%d %d %lld\n",i,n,sum);
}
return ;
}
 
上一篇:HA Joker Vulnhub Walkthrough


下一篇:505C Mr. Kitayuta, the Treasure Hunter