Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- /** 1/k = 1/x + 1/y
- When x and y are equal, they are both 2k.
- 1/k = 1/(2k) + 1/(2k)
- if x is larger than 2k, then y must be smaller than 2k.
- Since y can't be k, we only need to check y in [k+1, 2k].
- But how to compute x?
- 1/x = 1/k - 1/y
- = (y-k) / (k*y)
- So if y-k divides k*y, then x = (k*y) / (y-k).
- */
- int main()
- {
- int k;
- while(cin>>k)
- {
- int c=0;
- vector<pair<int,int>>v;
- for(int i=k+1;i<=2*k;i++)
- {
- if(i*k%(i-k)==0)
- {
- c++;
- v.push_back(make_pair((i*k)/(i-k),i));
- }
- }
- cout<<c<<endl;
- for(int i=0;i<v.size();i++){
- cout<<"1/"<<k<<" = 1/"<<v[i].first<<" + "<<"1/"<<v[i].second<<endl;;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment