首页 > 代码库 > UVA - 10976
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 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
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 (x, y) pairs, followed by a sorted list of the values of x and y, as shown in the sample output.
Sample Input
212
Sample Output
21/2 = 1/6 + 1/31/2 = 1/4 + 1/481/12 = 1/156 + 1/131/12 = 1/84 + 1/141/12 = 1/60 + 1/151/12 = 1/48 + 1/161/12 = 1/36 + 1/181/12 = 1/30 + 1/201/12 = 1/28 + 1/211/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 }
UVA - 10976
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。