首页 > 其他 > 详细

10820 - Send a Table

时间:2015-03-24 16:12:28      阅读:240      评论:0      收藏:0      [点我收藏+]

用欧拉phi函数值算出每个数与他互素的整数的个数。

#include<bits/stdc++.h>
using namespace std;
int solve(int n,int* phi){
    for(int i=2;i<=n;i++) phi[i] = 0;
    phi[1] = 1;
    int max_phi=0;
    for(int i=2;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-1);
    }
    for(int i=2;i<=n;i++)
        max_phi+=phi[i];
    return max_phi;
}
int phi[50005],n;

int main() {
    while(scanf("%d",&n)!=EOF&&n) {
        printf("%d\n",2*solve(n,phi)+1);
    }
    return 0;
}


10820 - Send a Table

原文:http://blog.csdn.net/weizhuwyzc000/article/details/44593039

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!