Fork me on GitHub

POJ 3090 Visble Lattice Points

问题转化为求1-n的欧拉函数的和*2+1

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#define LL long long
#define M 1009
using namespace std;
int phi[M],prime[M];
bool notp[M];
int sum,tot,ans;
void getphi()
{
    phi[1]=1;
    for(int i=2;i<=M;i++)
    {
        if(!notp[i]) 
        {
            phi[i]=i-1;
            prime[++tot]=i;
        }
        for(int j=1;j<=tot&&i*prime[j]<=M;j++)
        {
            notp[i*prime[j]]=1;
            if(i%prime[j]==0)
            {
                phi[i*prime[j]]=prime[j]*phi[i];
                break;
            }
            else phi[i*prime[j]]=(prime[j]-1)*phi[i];
        }
    }
}
int main()
{
    notp[1]=1,notp[0]=1;
    getphi();
    int c,p;
    scanf("%d",&c);
    for(int i=1;i<=c;i++)
    {
        ans=0;
        scanf("%d",&p);
        for(int j=1;j<=p;j++)
         ans+=phi[j];
        printf("%d %d %d\n",i,p,2*ans+1);
    }
    return 0;
} 
posted @ 2017-09-24 17:48  primes  阅读(79)  评论(0编辑  收藏  举报