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

luogu_2158 [SDOI2008]仪仗队

时间:2017-10-07 18:50:53      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:pre   names   特殊   ref   const   for   ati   scanf   函数   

//欧拉函数:

欧拉函数是积性函数——若m,n互质
技术分享
特殊性质:当n为奇数时,
 技术分享 
若n为质数则
技术分享
 
#include <cstdio>
#include <iostream>
using namespace std;
const int N=40010;
int n,p[N],nop[N],cnt,phi[N],ans;

int main(){
    scanf("%d",&n);
    if(n==0){puts("0"); return 0;}
    nop[1]=1;
    for(int i=2;i<=n;i++){
        if(!nop[i]){p[++cnt]=i; phi[i]=i-1;}
        for(int j=1;j<=cnt && i*p[j]<=n;j++){
            nop[i*p[j]]=1;
            if(i%p[j]==0){phi[i*p[j]]=phi[i]*p[j]; break;}
            else phi[i*p[j]]=phi[i]*(p[j]-1);
        }
    }
    for(int i=2;i<=n-1;i++)ans+=phi[i];
    printf("%d\n",ans*2+3);
    return 0;
}

  

luogu_2158 [SDOI2008]仪仗队

标签:pre   names   特殊   ref   const   for   ati   scanf   函数   

原文地址:http://www.cnblogs.com/codetogether/p/7635315.html

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