码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 10976

时间:2014-11-26 14:16:39      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

Problem A: Fractions Again?!

Time limit: 1 second

It is easy to see that for every fraction in the form bubuko.com,布布扣 (k > 0), we can always find two positive integers x and yx ≥ y, such that: 

bubuko.com,布布扣.

Now our question is: can you write a program that counts how many such pairs of x and y there are for any given k?

 

Input

Input contains no more than 100 lines, each giving a value of k (0 < k ≤ 10000).

 

Output

For each k, output the number of corresponding (xy) pairs, followed by a sorted list of the values of x and y, as shown in the sample output.

 

Sample Input

2
12

 

Sample Output

2
1/2 = 1/6 + 1/3
1/2 = 1/4 + 1/4
8
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

 

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 
 5 using namespace std;
 6 
 7 char ch[1000][50];
 8 int main () {
 9     int n;
10     while (cin >> n) {
11         int pos = 0;
12         for (int i = n + 1;i <= 2 * n;i++) {
13             if (i * n % (i - n) == 0) {
14                 sprintf(ch[pos++],"1/%d = 1/%d + 1/%d\n",n,i * n / (i - n),i);
15             }
16         }
17         cout << pos << endl;
18         for (int i = 0;i < pos;i++) {
19             cout << ch[i];
20         }
21     }
22 }
View Code

 

UVA - 10976

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/xiaoshanshan/p/4123002.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!