题目大意:给一个k,寻找出所有使1/k=1/a+1/b(a>b)成立的所有a和b。
题目分析:枚举b,从k+1枚举到2*k。
代码如下:
# include<iostream> # include<cstdio> # include<cstring> # include<algorithm> using namespace std; int v[10000]; int main() { int k; while(~scanf("%d",&k)) { int cnt=0; for(int b=k+1;b<=2*k;++b) if((k*b)%(b-k)==0) v[cnt++]=b; printf("%d ",cnt); for(int i=0;i<cnt;++i) printf("1/%d = 1/%d + 1/%d ",k,(v[i]*k)/(v[i]-k),v[i]); } return 0; }