10976 - Fractions Again?!

来源:互联网 发布:外盘配资端口 编辑:程序博客网 时间:2024/06/03 20:06

Fractions Again?!

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

1k=1x+1y

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<k10000).

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

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

输入正整数k,找到所有的正整数x≥y,使得1k=1x+1y

样例输入:

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

//#define LOCAL#include <iostream>#include <cstdio>using namespace std;const int maxNum = 1005;int main() {    #ifdef LOCAL        freopen("data.10976.in", "r", stdin);        freopen("data.10976.out", "w", stdout);    #endif // LOCAL    int k;    while(cin >> k) {        int x, y;        int num = 0;        int ax[maxNum];        int ay[maxNum];        for(y = k + 1; y <= 2 * k; y++) {            // x是否为整数            int isInteger = (y * k) % (y - k);            // 整数且x>=y            if(isInteger == 0) {                x = (y * k) / (y - k);                if(x >= y) {                    ax[num] = x;                    ay[num] = y;                    num++;                }            }        }        cout << num << endl;        for(int i = 0; i < num; i++) {            printf("1/%d = 1/%d + 1/%d\n", k, ax[i], ay[i]);        }    }    return 0;}
0 0
原创粉丝点击