10976:Fractions Again?!
x 要用 long long。
#include<bits/stdc++.h>
using namespace std;
const int maxk = 10000;
int k;
long long x[2*maxk];
int y[2*maxk];
int judge(int y)
{
long long x = k*y/(y-k);
if(x*y/(x+y) == k) return x;
return 0;
}
int main()
{
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
while(scanf("%d",&k) != EOF){
int cnt = 0;
for(int i = k+1;i <= 2*maxk;i++){
x[cnt] = judge(i);
if(x[cnt] && x[cnt] < i) break;
if(x[cnt]) y[cnt++] = i;
}
printf("%d\n",cnt);
for(int i = 0;i < cnt;i++){
printf("1/%d = 1/%lld + 1/%d\n",k,x[i],y[i]);
}
}
return 0;
}
Email:JingwangLi@outlook.com