forked from kingroryg/DSA
-
Notifications
You must be signed in to change notification settings - Fork 2
/
EulerTotient.cpp
51 lines (47 loc) · 881 Bytes
/
EulerTotient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//saru95
#include <fstream>
#include <iostream>
#include <string>
#include <cstring>
#include <complex>
#include <math.h>
#include <utility>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <cctype>
#include <queue>
#include <stdio.h>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <numeric>
#include <memory.h>
#define all(a) (a).begin(),(a).end()
#define gcd __gcd
#define bitcount __builtin_popcount
using namespace std;
int phi(int n) {
int result = n ;
for(int i=2;i*i<=n;++i) {
if(n%i==0){
while(n%i==0){
n = n / i ;
}
result = result - (result/i) ;
}
}
if(n>1)
result = result - (result/n) ;
return result ;
}
int main(int argc, char const *argv[]) {
int n , result ;
cin >> n ;
result = phi(n) ;
cout << result << endl ;
return 0;
}