Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int EulerTotientFunction(int n) {
- // Sample
- int ans = n;
- int sq = sqrt(n);
- for(int i = 2; i <= sq; ++i) {
- if(n % i == 0) {
- while(n % i == 0)
- n /= i;
- ans -= ans / i;
- }
- }
- if(n > 1)
- ans -= (ans / n);
- return ans;
- }
Add Comment
Please, Sign In to add comment