POJ 3090 欧拉函数

求一个平面内可见的点,其实就是坐标互质即可,很容易看出来或者证明

所以求对应的欧拉函数即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int phi[1010];
int n;
void calc(int x)
{
    for (int i=2;i<=x;i++) phi[i]=0;
    phi[1]=1;
    for (int i=2;i<=x;i++){
        if (!phi[i])
        for (int j=i;j<=x;j+=i){
            if (!phi[j]) phi[j]=j;
            phi[j]=phi[j]/i*(i-1);
        }

    }
}
int main()
{
    int t,kase=0;
    scanf("%d",&t);
    calc(1001);
    while (t--)
    {
        scanf("%d",&n);
        n;
        int ans=3;
        for (int i=2;i<=n;i++){
            ans+=2*phi[i];
        }
        //ans+=2*phi[n];
        printf("%d %d %d\n",++kase,n,ans);
    }
}

 

posted @ 2014-09-08 16:49  KRisen  阅读(140)  评论(0编辑  收藏  举报