Advertisement
istinishat

Euler phi function

Nov 3rd, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int phi(int n)
  5. {
  6.     int result=n;
  7.  
  8.     for(int i=2;i*i<=n;i++){
  9.         if(n%i==0){
  10.             while(n%i==0)
  11.                 n/=i;
  12.             result-=(result/i);
  13.         }
  14.     }
  15.     if(n>1)
  16.         result-=(result/n);
  17.  
  18.     return result;
  19. }
  20.  
  21.  
  22. int main()
  23. {
  24.     int i;
  25.     while(1){
  26.         cin>>i;
  27.         cout<<"Value of phi("<<i<<") : "<<phi(i)<<endl;
  28.     }
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement