We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4314dd9 commit 87ace8aCopy full SHA for 87ace8a
C++/euler_totient_func.cpp
@@ -0,0 +1,43 @@
1
+#include<cstdio>
2
+#include<iostream>
3
+
4
+int phi[1000006], prime[1000006];
5
+void sievephi(int n)
6
+{
7
+ int i,j;
8
9
+ for(i=1; i<=n; i++) phi[i]=i;
10
11
+ phi[1]=1;
12
+ prime[1]=1;
13
14
+ for(i=2; i<=n; i++)
15
+ {
16
+ if(!prime[i])
17
18
+ for(j=i;j<=n; j+=i)
19
20
+ prime[j+i]=1;
21
+ phi[j]=(phi[j]/i)*(i-1);
22
23
+ }
24
25
26
+}
27
28
29
+int main()
30
31
+ int i,n=10;
32
+ sievephi(n);
33
34
+ for(i=1; i<=n; i++)
35
36
+ printf("%d ", i);
37
+ printf("\n");
38
39
40
+ printf("%d = %d\n", i, phi[i]);
41
42
+ return 0;
43
0 commit comments