题目链接:
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37234
题目描述:
输入正整数k,找到所有正整数 x>=y,使得1/k = 1/x + 1/y.
思路:
因为 x>=y 所以有: 1/k <= 1/y + 1/y –> 1/k <= 2/y –> y <= 2k. 又因为 1/k = 1/y + 1/x –> k*y / (y-k) = x, 即当 k*y % (y-k) == 0时,必然得整数x,此对xy为一解。
/*************************************************************************
> File Name: UVa_10976.cpp
> Author: dulun
> Mail: dulun@xiyoulinux.org
> Created Time: 2016年03月19日 星期六 00时45分43秒
************************************************************************/
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define LL long long
using namespace std;
const int N = 1086;
int x[N];
int Y[N];
int main()
{
int k;
while(~scanf("%d", &k))
{
int sum = 0;
int k2 = k<<1;
for(int y = k+1; y <= k2; y++)
{
if(k * y % (y - k) == 0)
{
x[sum] = k*y / (y-k);
Y[sum] = y;
sum++;
}
}
printf("%d\n", sum);
for(int i = 0; i < sum; i++) printf("1/%d = 1/%d + 1/%d\n", k, x[i], Y[i]);
}
return 0;
}