题目:
输入正整数K,找出所有的正整数X>=y,使得1 / k = 1 / x + 1 / y;
分析:
易得y > k 且 y <= 2 * k
#include <stdio.h>
#include <iostream>
using namespace std;
const int maxn = 105;
int pos;
int ax[maxn], ay[maxn];
int main()
{
int k;
scanf("%d", &k);
int cnt = 0;
for (int y = k + 1; y <= 2 * k; ++y)
{
double x = 1.0 * k * y / (y - k);
if (x == (int)x)
{
ax[pos] = (int)x;
ay[pos] = y;
++pos;
++cnt;
}
}
printf("%d\n", cnt);
for (int w = 0; w < pos; ++w)
printf("1/%d = 1/%d + 1/%d\n", k, ax[w], ay[w]);
return 0;
}