标签:编程
现在输入一个正整数k,找到所有的正整数x>=y,使得1/k=1/x+1/y.
2 2 12
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
#include<stdio.h> int main() { int n,k,x,y; scanf("%d",&n); while(n--) { scanf("%d",&k); int i=1; y=k; do{ y++; if((k*y)%i==0) { x=(k*y)/i; printf("1/%d=1/%d+1/%d\n",k,x,y); } i++; }while(x>y); } return 0; }
标签:编程
原文地址:http://blog.csdn.net/xialiufufeng/article/details/42739763