1 /*
2 输入正整数k,找到所有的正整数x>=y,使得1/k = 1/x + 1/y.
3 样例输入:
4 2
5 12
6 样例输出
7 2
8 1/2=1/6+1/3
9 1/2=1/4+1/4
10
11 8
12 1/12 = 1/156 + 1/13
13 1/12 = 1/84 + 1/14
14 1/12 = 1/60 + 1/15
15 1/12 = 1/48 + 1/16
16 1/12 = 1/36 + 1/18
17 1/12 = 1/30 + 1/20
18 1/12 = 1/28 + 1/21
19 1/12 = 1/24 + 1/24
20 */
21 #include <stdio.h>
22
23 const int MAXN = 1000 + 10;
24 int x[MAXN],y[MAXN];
25
26 int main()
27 {
28 int k;
29 int ans;
30 int i;
31 while (scanf("%d",&k) != EOF)
32 {
33 ans = 0;
34 for (i = k + 1; i <= 2*k; ++i)
35 {
36 if ((k * i) % (i-k) == 0) { x[ans] = (k*i)/(i-k),y[ans++] = i; }
37 }
38 printf("%d\n",ans);
39 for (i = 0; i < ans; ++i)
40 {
41 printf("1/%d = 1/%d + 1/%d\n",k,x[i],y[i]);
42 }
43 }
44 return 0;
45 }
46
posted on 2011-10-07 17:04
nk_ysg 阅读(517)
评论(0) 编辑 收藏 引用 所属分类:
算法