Last active
February 23, 2017 16:49
-
-
Save tahmidrafi/bea080b35288026de0d73ed6ea1fb541 to your computer and use it in GitHub Desktop.
This file contains hidden or 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<stdio.h> | |
| int phi[1000006], mark[1000006]; | |
| void seivephi(int n) | |
| { | |
| int i, j; | |
| for(i=1; i<=n; i++) phi[i] = i; | |
| phi[1] = 1; | |
| mark[1] = 1; | |
| for(i=2; i<=n; i++) | |
| if(!mark[i]) | |
| for(j=i; j<=n; j+=i) | |
| { | |
| mark[j] = 1; | |
| phi[j] = phi[j] / i * (i-1); | |
| } | |
| } | |
| int main() | |
| { | |
| int n = 30, i; | |
| seivephi(n); | |
| printf(" i: "); | |
| for(i=1; i<=n; i++) | |
| printf("%3d%c", i, i<n?' ':'\n'); | |
| printf(" phi: "); | |
| for(i=1; i<=n; i++) | |
| printf("%3d%c", phi[i], i<n?' ':'\n'); | |
| printf("mark: "); | |
| for(i=1; i<=n; i++) | |
| printf("%3d%c", mark[i], i<n?' ':'\n'); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment