Advertisement
Cati29

phi

Dec 8th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1.  
  2. int Phi(int n)
  3. {
  4. int d,p;
  5. double phi;
  6. phi = n;
  7. d = 2;
  8. while(n != 1)
  9. {
  10. p = 0;
  11. while (n % d ==0)
  12. {
  13. p++;
  14. n/=d;
  15. }
  16. if(p > 0) phi *= (d-1) * 1./d;
  17. if(d * d < n) d ++;
  18. else d = n;
  19. }
  20. return int(phi);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement