UVA - 10976

Problem A: Fractions Again?!

Time limit: 1 second

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

.

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

 

 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

 

posted @ 2014-11-26 13:11  闪光阳  阅读(240)  评论(0)    收藏  举报