UVA 10976 Fractions Again?!
题意:
输入一个正整数k,找出所有正整数x>=y,使得1/k=1/x+1/y
分析:
x>=y退出1/x<=1/y,所以1/k-1/y<=1/y,所以y<=2k;枚举y
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int k;
int x[10011],y[10011];
int main()
{
int cnt;int i;
while(~scanf("%d",&k))
{
cnt=0;
for(i=k+1;i<=2*k;i++)
{
if((k*i)%(i-k)==0)
{
y[cnt]=i;
x[cnt]=(k*i)/(i-k);
cnt++;
}
}
printf("%d\n",cnt);
for (i=0;i<cnt;++i)
printf("1/%d = 1/%d + 1/%d\n",k,x[i],y[i]);
}
}