Advertisement
Pabon_SEC

Fractions Again

May 13th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<pair<int,int>>vec;
  6.  
  7. int main()
  8. {
  9.     int k,i,y,cnt;
  10.  
  11.     while(~scanf("%d",&k))
  12.     {
  13.         double x;
  14.  
  15.         cnt = 0;
  16.  
  17.         for(y=k+1; y<=2*k; y++)
  18.         {
  19.             if((k*y)%(y-k))
  20.                 continue;
  21.  
  22.             x = (k*y)/(y-k);
  23.  
  24.             if(x<y)
  25.                 break;
  26.  
  27.             if((x*y)/(x+y)==k)
  28.             {
  29.                 vec.push_back(make_pair(int(x),y));
  30.  
  31.                 cnt++;
  32.             }
  33.         }
  34.  
  35.         printf("%d\n",cnt);
  36.  
  37.         for(auto z : vec)
  38.         {
  39.             printf("1/%d = 1/%d + 1/%d\n",k,z.first,z.second);
  40.         }
  41.  
  42.         vec.clear();
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement