首页 > 其他 > 详细

暴力枚举 UVA 10976 Fractions Again?!

时间:2015-04-28 18:15:39      阅读:83      评论:0      收藏:0      [点我收藏+]

 

题目传送门

 1 /*
 2     x>=y, 1/x <= 1/y, 因此1/k - 1/y <= 1/y, 即y <= 2*k
 3 */
 4 #include <cstdio>
 5 #include <iostream>
 6 #include <algorithm>
 7 #include <cmath>
 8 #include <cstring>
 9 #include <string>
10 #include <map>
11 #include <set>
12 #include <queue>
13 using namespace std;
14 
15 const int MAXN  = 1e4 + 10;
16 const int INF = 0x3f3f3f3f;
17 struct NODE
18 {
19     int x, y;
20 }node[MAXN];
21 
22 int main(void)        //UVA 10976 Fractions Again?!
23 {
24     //freopen ("UVA_10976.in", "r", stdin);
25 
26     int k;
27     while (scanf ("%d", &k) == 1)
28     {
29         int cnt = 0;
30         for (int i=k+1; i<=2*k; ++i)
31         {
32             if ((i*k) % (i-k) == 0)
33             {
34                 node[++cnt].x = (i*k) / (i-k);
35                 node[cnt].y = i;
36             }
37         }
38 
39         printf ("%d\n", cnt);
40         for (int i=1; i<=cnt; ++i)
41         {
42             printf ("1/%d = 1/%d + 1/%d\n", k, node[i].x, node[i].y);
43         }
44     }
45 
46     return 0;
47 }
48 
49 /*
50 2
51 1/2 = 1/6 + 1/3
52 1/2 = 1/4 + 1/4
53 8
54 1/12 = 1/156 + 1/13
55 1/12 = 1/84 + 1/14
56 1/12 = 1/60 + 1/15
57 1/12 = 1/48 + 1/16
58 1/12 = 1/36 + 1/18
59 1/12 = 1/30 + 1/20
60 1/12 = 1/28 + 1/21
61 1/12 = 1/24 + 1/24
62 */

 

暴力枚举 UVA 10976 Fractions Again?!

原文:http://www.cnblogs.com/Running-Time/p/4463248.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!