Do It Wrong, Get It Right
Do It Wrong, Get It Right |
Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB |
Total submit users: 7, Accepted users: 6 |
Problem 12627 : No special judgement |
Problem description |
In elementary school, students learn to subtract fractions by first getting a common denominator and then subtracting the numerators. However, sometimes a student will work the problem incorrectly and still arrive at the correct answer. For example, for the problem 5 9 4 12 one can subtract the numbers in the numerator and then subtract the numbers in the denominator, simplify and get the answer. i.e.
|
Input |
There will be several test cases in the input. Each test case will consist of a single line with two integers, b and n (1 ≤ b,n ≤ 106) separated by a single space. The input will end with a line with two 0s. |
Output |
For each case, output all of the requested fractions on a single line, sorted from smallest to largest. For equivalent fractions, print the one with the smaller numerator first. Output each fraction in the form “a/m” with no spaces immediately before or after the “/”. Output a single space between fractions. Output no extra spaces, and do not separate answers with blank lines. |
Sample Input |
9 12 12 14 4 12 0 0 |
Sample Output |
0/24 5/20 8/16 8/8 5/4 0/28 9/21 9/7 0/24 3/18 3/6 |
Problem Source |
ACM ICPC Southeast USA Regional Programming Contest 2012 |
可以枚举m或者a,如果枚举a,计算m涉及到开方操作,所以比较慢,会超时;所以只能枚举m,从2*n枚举到1就可以了。
long long输入输出要用%I64d!一直用的是%lld,纠结了好久啊!!!!
#include <cstdio> #include <cmath> #include <cstdlib> #define LL long long int main(void) { LL b, n; freopen("in.txt", "r", stdin); while (~scanf("%I64d%I64d", &b, &n)) // while (~scanf("%lld%lld", &b, &n)) { ) break; printf(*n); *n - ;m>;m--) { *n-m))%(n*n)==) printf(*n-m))/(n*n),m); } printf("\n"); } ; }
嗨,中村。
随机推荐
- End Routine
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- Sprint(第一天11.14)
Sprint1第一阶段 1.类名:软件工程-第一阶段 2.时间:11.14-11.23 3.选题内容:点餐系统 4.团队博客地址:http://www.cnblogs.com/iamCarson/ 团 ...
- Quick-Cocos2d-x初学者游戏教程1
Quick-Coco2d-x安装: Quick 安装完成后,在它的根目录下可以找到有两个名为setup_mac.sh.setup_win.bat的批处理脚本,它们分别是搭建Mac和Windows开发环 ...
- hdu3652 B-number
链接 题意求能够整除和包含13的数字. 这个比较简单,保留余数及1,然后标记前面是否出现过13就行. #include <iostream> #include<cstdio> ...
- 编写高效且优雅的 Python 代码
http://python.jobbole.com/86808/ http://python.jobbole.com/86869/?utm_source=blog.jobbole.com&ut ...
- linux笔记:用户和用户组管理-用户管理命令
useradd(添加用户.在使用useradd添加一个用户后,必须使用passwd给该用户设置密码,该用户才能登陆): passwd(设置或修改用户密码): usermod(修改用户信息): chag ...
- django rest framework csrf failed csrf token missing or incorrect
django rest framework csrf failed csrf token missing or incorrect REST_FRAMEWORK = { 'DEFAULT_AUTHEN ...
- NGINX 内存池有感
写在前面 写NGINX系列的随笔,一来总结学到的东西,二来记录下疑惑的地方,在接下来的学习过程中去解决疑惑. 也希望同样对NGINX感兴趣的朋友能够解答我的疑惑,或者共同探讨研究. 整个NGINX系列 ...
- jquery实现自动滚屏效果,适用用公告新闻等滚屏
从网络上找到的例子,自己做了下扩展,原示例是向上滚动,扩展了一个向下滚动的方法: <html xmlns="http://www.w3.org/1999/xhtml"> ...
- OC语言构造方法
OC语言构造方法 一.构造方法 (一)构造方法的调用 完整的创建一个可用的对象:Person *p=[Person new]; New方法的内部会分别调用两个方法来完成2件事情,1)使用alloc方法 ...