Advertisement
a53

Phi

a53
Oct 20th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. int Phi(int n)
  2. {
  3. int d;
  4. unsigned long long int nrp=n,prod=1;
  5. if(n%2==0)
  6. {
  7. while(n%2==0)
  8. n/=2;
  9. nrp*=(2-1),prod*=2;
  10. }
  11. d=3;
  12. while(n>1)
  13. {
  14. if(n%d==0)
  15. {
  16. while(n%d==0)
  17. n/=d;
  18. nrp*=d-1,prod*=d;
  19. }
  20. else
  21. d+=2;
  22. if(n>1&&d*d>n)
  23. {
  24. nrp*=n-1,prod*=n;
  25. break;
  26. }
  27. }
  28. return (int) (nrp/prod);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement