Skip to content

Commit

Permalink
Merge pull request rathoresrikant#551 from z3r0dmg/patch-5
Browse files Browse the repository at this point in the history
Euler Totient function
  • Loading branch information
Srikant Singh authored Oct 27, 2018
2 parents 4fdfc1e + 8ddae3e commit 7fa71bb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Algorithms/Mathematical Algorithms/EulerTotient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>

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 /= i;
result -= result / i;
}
}
if(n > 1)
result -= result / n;
return result;
}

int main(){

int n;
cin>>n;
cout<<phi(n);
cout<<'\n';
}

0 comments on commit 7fa71bb

Please sign in to comment.