码迷,mamicode.com
首页 > 其他好文 > 详细

uva 10820

时间:2017-04-25 23:34:59      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:mem   void   memset   code   namespace   div   turn   cstring   color   

欧拉函数。。。。。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=50000+10;
int pp[maxn];
int sum[maxn];
int n;
void ola()
{
    memset(pp,0,sizeof(pp));
    memset(sum,0,sizeof(sum));
    pp[1]=1;
    for(int i=2;i<=maxn;i++)
        if(!pp[i])
        {
            for(int j=i;j<=maxn;j+=i)
            {
                if(!pp[j]) pp[j]=j;
                pp[j]=pp[j]/i*(i-1);
            }
        }
        for(int i=1;i<=maxn;i++)
            sum[i]=pp[i]+sum[i-1];
}
int main()
{   ola();
    while(~scanf("%d",&n)&&n!=0)
    {
        printf("%d\n",sum[n]*2-1);
    }
    return 0;
}

 

uva 10820

标签:mem   void   memset   code   namespace   div   turn   cstring   color   

原文地址:http://www.cnblogs.com/Wangwanxiang/p/6765058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!