当前位置: 代码迷 >> 综合 >> UVa 10976 Fractions Again?!(分数拆分)
  详细解决方案

UVa 10976 Fractions Again?!(分数拆分)

热度:56   发布时间:2023-12-08 11:21:01.0

题目链接:UVa 10976

题意:

输入一个正整数k,找到所有的正整数x>y,使得1/k=1/x+1/y。


CODE:

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;int x[10010], y[10010], k, cnt;int main()
{
#ifdef LOCALfreopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
#endif while (cin >> k){cnt = 0;for (int i = k+1; i <= 2 * k; i++){if (k*i % (i - k)) continue;y[cnt] = i;x[cnt++] = k*i / (i - k);}cout << cnt << endl;for (int i = 0; i < cnt; i++)printf("1/%d = 1/%d + 1/%d\n", k, x[i], y[i]);}return 0;
}