标签: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 (k > 0), we can always find two positive integers x and y, x ≥ 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 contains no more than 100 lines, each giving a value of k (0 < k ≤ 10000).
For each k, output the number of corresponding (x, y) pairs, followed by a sorted list of the values of x and y, as shown in the sample output.
2 12
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 }
标签:style blog http io ar color os sp for
原文地址:http://www.cnblogs.com/xiaoshanshan/p/4123002.html