http://poj.org/problem?id=3090
求出互质的数对\((x,y)\)个数
\((x,y)\)与\((y,x)\)算两对,要乘\(2\),不过\((1,1)\)需要特判
还有水平、垂直两种情况
\(C++ Code:\)
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 1005
#define ll long long
using namespace std;
int cnt,phi[N],prime[N];
ll sphi[N];
bool pri[N];
int T,n,c;
void Pre()
{
sphi[1]=phi[1]=1;
for (int i=2;i<=N;i++)
{
if (!pri[i])
{
prime[++cnt]=i;
phi[i]=i-1;
}
for (int j=1;j<=cnt;j++)
{
ll g=(ll)i*prime[j];
if (g>N)
break;
pri[g]=true;
if (i%prime[j]==0)
{
phi[g]=phi[i]*prime[j];
break;
}
phi[g]=phi[i]*(prime[j]-1);
}
sphi[i]=sphi[i-1]+phi[i];
}
}
int main()
{
Pre();
scanf("%d",&c);
while (c --> 0)
{
scanf("%d",&n);
T++;
printf("%d %d %lld\n",T,n,(sphi[n] << 1)+1);
}
return 0;
}
POJ3090 Visible Lattice Points
原文:https://www.cnblogs.com/GK0328/p/13398502.html