UVa 10976 Fractions Again?!
题意:给出正整数k,找到所有整数使得满足1/k=1/x+1/y
根据基本不等式可以求出k<=y<=2k,在这个范围内枚举即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8 #include<queue> 9 #include<algorithm> 10 #define mod=1e9+7; 11 using namespace std; 12 13 typedef long long LL; 14 15 int main(){ 16 int k,i,j,a,b,x,y; 17 while(cin>>k){ 18 int ans=0; 19 for(y=1;y<=2*k;y++){ 20 if(y!=k) x=(k*y)/(y-k);//注意分母为0的情况 21 int m=k*(x+y)-x*y; 22 if(x>=y&&m==0) ans++; 23 } 24 printf("%d\n",ans); 25 26 for(y=1;y<=2*k;y++){ 27 if(y!=k) x=(k*y)/(y-k); 28 int m=k*(x+y)-x*y; 29 if(x>=y&&(m==0)) 30 printf("1/%d = 1/%d + 1/%d\n",k,x,y); 31 } 32 } 33 return 0; 34 }