UVA 10976 - Fractions Again?!
2015-07-29 14:42
519 查看
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1917
题 意:给你一个k,找出所有满足x>=y 1/k=1/x+1/y的x,y。
思 路:由x>=y,有 1/x<=1/y且1/k-1/y<=1/y所以y<=2*k,又因为1/k>1/y所以有y>k因而直接在(k,2*k]内枚举x即可。
代码如下:
题 意:给你一个k,找出所有满足x>=y 1/k=1/x+1/y的x,y。
思 路:由x>=y,有 1/x<=1/y且1/k-1/y<=1/y所以y<=2*k,又因为1/k>1/y所以有y>k因而直接在(k,2*k]内枚举x即可。
代码如下:
#include <iostream> using namespace std; #include <string.h> #include <stdio.h> #include <queue> #include <algorithm> typedef long long LL; int x[100000],y[100000]; int main() { int k; while( scanf ( "%d", &k ) != EOF ) { int j = 0; for( int i = k+1; i <= k*2; i ++ ) { if( i*k % (i-k) == 0 ) x[j]=i*k/(i-k),y[j++]=i; } printf("%d\n",j); for( int i = 0; i < j; i ++ ) { printf("1/%d = 1/%d + 1/%d\n",k,x[i],y[i]); } } return 0; }
相关文章推荐
- 用fail2ban阻止SSH和VSFTP暴力破解密码
- 2015BJOI day1第三题 糖果candy
- 4495: Least Prime factor 找到最小质因子P的第N小正整数
- POJ 2965.The Pilots Brothers' refrigerator
- POJ 1753.Flip Game
- POJ 3295.Tautology
- 没参加的2015百度之星——数矩形
- Birthday Cake——直线分割
- Spiral——找规律暴力
- POJ 1166&IOI 1994 The blocks 暴力枚举 解题报告
- hdu 1248
- LCM Challenge(暴力)
- 小晴天老师系列——竖式乘法(暴力)
- URAL 1786 Sandro's Biography
- URAL 1788 On the Benefits of Umbrellas
- URAL 1792 Hamming Code
- URAL 1794 Masterpieces of World Architecture
- URAL 1796 Amusement Park
- HDU 5207 Greatest Greatest Common Divisor
- HDU3183 A 4000 Magic Lamp