10976 - Fractions Again?!
来源:互联网 发布:外盘配资端口 编辑:程序博客网 时间:2024/06/03 20:06
Fractions Again?!
It is easy to see that for every fraction in the form
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
Output
For each k, output the number of corresponding
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;}
- UVA 10976 - Fractions Again?!
- UVA 10976 - Fractions Again?!
- UVA-10976 - Fractions Again?!
- UVA - 10976 Fractions Again?!
- UVa 10976 - Fractions Again?!
- UVa 10976 - Fractions Again?!
- UVa 10976 - Fractions Again?!
- UVA - 10976 Fractions Again?!
- uva 10976 - Fractions Again?!
- 10976 - Fractions Again?!
- 10976 - Fractions Again!
- UVa 10976 Fractions Again?!
- Uva - 10976 - Fractions Again?!
- UVA - 10976 Fractions Again?!
- uva 10976Fractions Again?!
- UVA 10976 - Fractions Again?!
- UVA 10976 Fractions Again?!
- UVA 10976 Fractions Again?!
- C++与类相关的关键词和修饰符说明
- git创建:error: could not lock config file
- UI基础_UIButton
- IOS本地推送即IOS备忘提醒实现
- 打包错误 No codesigning identities found:
- 10976 - Fractions Again?!
- TCP通信流程解析
- SQL SERVER 时间和日期函数
- RSA算法及其相应的理论知识
- 减少C++代码编译时间的方法
- SDUT 1489 求二叉树的先序遍历
- 机器学习中各种距离计算
- 《新手学HTML5》学习笔记
- linux下的irda (remote control)驱动分析