UVA 10976 - Fractions Again?!
分数表达式-------------计算1/k = 1/x + 1/y;
Sample Input |
2 2 12 |
Sample Output |
1/2=1/6+1/3 1/2=1/4+1/4 1/12=1/156+1/13 1/12=1/84+1/14 1/12=1/60+1/15 1/12=1/48+1/16 1/12=1/36+1/18 1/12=1/30+1/20 1/12=1/28+1/21 1/12=1/24+1/24 |
Code
:
1 # include<iostream> 2 # include<cstdio> 3 using namespace std; 4 int main() 5 { 6 int n; 7 cin>>n; 8 int x,y,k; 9 int cnt = 0; 10 while(n--) 11 { 12 cin>>k; 13 if(cnt!=0) 14 { 15 cout<<endl; 16 } 17 for(int y=k+1; y<=2*k; y++)//之所以为2×K是因为 18 以1/2 = 1/4+1/4;顶多循环到二倍即4 19 { 20 if((k*y)%(y-k)==0) { 21 int x=(k*y)/(y-k); 22 cout<<"1/"<<k<<"=1/"<<x<<"+1/"<<y<<endl; 23 } 24 } 25 cnt++; 26 } 27 return 0; 28 }