We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ae19f0d commit b650126Copy full SHA for b650126
euler_totient.cpp
@@ -0,0 +1,53 @@
1
+#include<iostream>
2
+#include<vector>
3
+#include<map>
4
+using namespace std;
5
+#define MAX 1000005
6
+long long phi[MAX];
7
+void generatePhi()
8
+{
9
+
10
+ phi[1]=1;
11
+ for(int i=2; i<MAX; i++)
12
+ {
13
+ if(phi[i]==0)
14
15
+ phi[i]=i-1;
16
+ for(int j=(i<<1);j<MAX;j=j+i)
17
18
+ if(!phi[j])
19
+ phi[j]=j;
20
21
+ phi[j]=(phi[j]/i)*(i-1);
22
+ }
23
24
25
+}
26
27
+long long solutions[MAX];
28
+int main()
29
30
+ generatePhi();
31
32
33
+ for(int i=1; i<MAX; i++)
34
35
+ for(int j=2; i*j<MAX; j++)
36
+ solutions[i*j] += i*phi[j];
37
38
39
40
41
+ solutions[i] += solutions[i-1];
42
43
44
+ int t;
45
+ cin>>t;
46
+ while(t--)
47
48
+ int n;
49
+ cin>>n;
50
+ cout<<solutions[n]<<endl;
51
52
+ return 0;
53
0 commit comments