UVA 10976 Fractions Again?! (暴力预处理)
2016-05-17 21:44
330 查看
题意:给一个数字k,求可以得到1/k的两个分数的所有可能情况并打印出来
简单的暴力题,直接从k+1~2*k中枚举,有合题意的则记录下来并最后输出即可
代码如下
简单的暴力题,直接从k+1~2*k中枚举,有合题意的则记录下来并最后输出即可
代码如下
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; int a[20000+10]; int main() { int n; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); int sum=0; for(int i=n+1; i<=2*n; i++) { int t=(n*i)/(i-n); if(t>=i&&(n*i)%(i-n)==0) sum++; } printf("%d\n",sum); for(int i=n+1; i<=2*n; i++) { int t=(n*i)/(i-n); if(t>=i&&(n*i)%(i-n)==0) printf("1/%d = 1/%d + 1/%d\n",n,(n*i)/(i-n),i); } } }
相关文章推荐
- 用fail2ban阻止SSH和VSFTP暴力破解密码
- 1.10055 - Hashmat the brave warrior
- 2.10071 - Back to High School Physics
- 3.458 - The Decoder
- 4.694 - The Collatz Sequence
- 6.494 - Kindergarten Counting Game
- 7.490 - Rotating Sentences
- 8.414 - Machined Surfaces
- 9.488 - Triangle Wave
- A.457 - Linear Cellular Automata
- B.489 - Hangman Judge
- C.445 - Marvelous Mazes
- 1.10494 - If We Were a Child Again
- 2.424 - Integer Inquiry
- 3.10250 - The Other Two Trees
- 5.465 - Overflow
- 6.113 - Power of Cryptography
- 7.10161 - Ant on a Chessboard
- 8.621 - Secret Research
- 9.401 - Palindromes