现在的位置: 首页 > 综合 > 正文

2190: [SDOI2008]仪仗队

2018年04月25日 ⁄ 综合 ⁄ 共 603字 ⁄ 字号 评论关闭
#include<iostream>
#include<cstdio>
#define N 40001
using namespace std;
int n,tot,ans,phi[N],prime[N];
bool mark[N];
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=ch-'0';ch=getchar();}
    return x*f;
}
void getphi(){
	phi[1]=1;
	for(int i=2;i<=n;i++){
		if(!mark[i]){prime[++tot]=i;phi[i]=i-1;}
		for(int j=1;j<=tot;j++){
			if(i*prime[j]>n)break;
			mark[i*prime[j]]=1;
			if(i%prime[j]==0){phi[i*prime[j]]=phi[i]*prime[j];break;}
			else phi[i*prime[j]]=phi[i]*(prime[j]-1);
		}
	}
}
int main(){
	n=read();
	getphi();
	for(int i=1;i<n;i++)ans+=phi[i];
	printf("%d",2*ans+1);
	return 0;
}

抱歉!评论已关闭.