Guest User

Untitled

a guest
Jul 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. /** 1/k = 1/x + 1/y
  5. When x and y are equal, they are both 2k.
  6.  
  7. 1/k = 1/(2k) + 1/(2k)
  8.  
  9. if x is larger than 2k, then y must be smaller than 2k.
  10. Since y can't be k, we only need to check y in [k+1, 2k].
  11. But how to compute x?
  12. 1/x = 1/k - 1/y
  13. = (y-k) / (k*y)
  14.  
  15. So if y-k divides k*y, then x = (k*y) / (y-k).
  16. */
  17. int main()
  18. {
  19. int k;
  20. while(cin>>k)
  21. {
  22. int c=0;
  23. vector<pair<int,int>>v;
  24. for(int i=k+1;i<=2*k;i++)
  25. {
  26. if(i*k%(i-k)==0)
  27. {
  28. c++;
  29. v.push_back(make_pair((i*k)/(i-k),i));
  30. }
  31.  
  32. }
  33. cout<<c<<endl;
  34. for(int i=0;i<v.size();i++){
  35. cout<<"1/"<<k<<" = 1/"<<v[i].first<<" + "<<"1/"<<v[i].second<<endl;;
  36.  
  37. }
  38.  
  39. }
  40. return 0;
  41. }
Add Comment
Please, Sign In to add comment