Created
February 3, 2014 13:29
-
-
Save erjiaqing/8783802 to your computer and use it in GitHub Desktop.
线性欧拉筛+素数筛
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
using namespace std; | |
const int maxn=1e7+7; | |
int prime[maxn],phi[maxn],n,totprime; | |
int main() | |
{ | |
scanf("%lld",&n); | |
phi[1]=1; | |
for (int i=2;i<=n;i++) | |
{ | |
if (!phi[i]) | |
{ | |
prime[totprime++]=i; | |
phi[i]=i-1; | |
} | |
for (int j=0;j<totprime&&i*prime[j]<=n;j++) | |
{ | |
if (i%prime[j]) | |
phi[i*prime[j]]=phi[i]*(prime[j]-1); | |
else | |
{ | |
phi[i*prime[j]]=phi[i]*prime[j]; | |
break; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment