bhupixb

EulerTotientFunction

Jun 25th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.24 KB | None | 0 0
  1. int EulerTotientFunction(int n) {
  2. // Sample
  3. int ans = n;
  4. int sq = sqrt(n);
  5. for(int i = 2; i <= sq; ++i) {
  6. if(n % i == 0) {
  7. while(n % i == 0)
  8. n /= i;
  9. ans -= ans / i;
  10. }
  11. }
  12. if(n > 1)
  13. ans -= (ans / n);
  14. return ans;
  15. }
Add Comment
Please, Sign In to add comment