Advertisement
Glenpl

Untitled

Jun 16th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. #define MAX_SHORT_VALUE 32767 /* 2^15 - 1 */
  5.  
  6. int Phi(int i)
  7. {
  8.     if (i==1) return 1;
  9.     int res = i;
  10.  
  11.     if (i%2==0)
  12.     {
  13.         res -= res/2;
  14.         do {i/=2;}
  15.         while (i%2==0);
  16.     }
  17.  
  18.     for (int j = 3; j*j <= i; j += 2)
  19.         if (i%j==0)
  20.         {
  21.             res-=res/j;
  22.             do i/=j;
  23.             while (i%j==0);
  24.         }
  25.  
  26.     if (i>1) res-=res/i;
  27.     return res;
  28. }
  29.  
  30. int main()
  31. {
  32.     std::vector<int> result_numbers;
  33.     int n;
  34.     std::cin>>n;
  35.  
  36.     for( short x = 1; x < MAX_SHORT_VALUE; x++ )
  37.         if( Phi(x) == n )
  38.             result_numbers.push_back(x);
  39.  
  40.     for(auto x: result_numbers)
  41.         std::cout << x << " ";
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement