题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1917
题 意:给你一个k,找出所有满足x>=y 1/k=1/x+1/y的x,y。
思 路:由x>=y,有 1/x<=1/y且1/k-1/y<=1/y所以y<=2*k,又因为1/k>1/y所以有y>k因而直接在(k,2*k]内枚举x即可。
代码如下:
#include <iostream>
using namespace std;
#include <string.h>
#include <stdio.h>
#include <queue>
#include <algorithm>
typedef long long LL;
int x[100000],y[100000];
int main()
{
int k;
while( scanf ( "%d", &k ) != EOF )
{
int j = 0;
for( int i = k+1; i <= k*2; i ++ )
{
if( i*k % (i-k) == 0 )
x[j]=i*k/(i-k),y[j++]=i;
}
printf("%d\n",j);
for( int i = 0; i < j; i ++ )
{
printf("1/%d = 1/%d + 1/%d\n",k,x[i],y[i]);
}
}
return 0;
}