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"); } ; }
嗨,中村。
随机推荐
- 使用IE11抓包,防止在网页跳转时抓包数据被清除的方法
引:最近在研究使用python实现模拟登陆各大网站,在使用IE11进行抓包分析网站登陆的逻辑结构的时候,发现每次在抓包的时候,当网页跳转的时候,抓包数据会被清除,让我很是郁闷,最终在查阅相关资料以及自 ...
- 推荐10个bootstrap及其他框架的后台管理模板
相对于网站前台炫目多彩的设计,网址后台的设计模板貌似有点少,在这里推荐10个可以免费下载的~ 1.自适应超酷整站 win8风格的Bootstrap响应式网站后台管理模板-Apricot 2.boots ...
- ruby 资源收集
http://huacnlee.com/blog/archives/ 一个牛人李华顺的个人网站 http://api.rubyonrails.org/ 不错的ruby on rails学习网站 htt ...
- python成长之路【第三篇】:函数
1.函数基础 函数是python为了代码最大程度的重用和最小化代码冗余而提供的基本程序结构. 函数是一种设计工具,它能让程序员将复杂的系统分解为可管理的部件. 函数用于将相关功能打包并参数. pyth ...
- 【PHP】基于ThinkPHP框架搭建OAuth2.0服务
[PHP]基于ThinkPHP框架搭建OAuth2.0服务 http://leyteris.iteye.com/blog/1483403
- json和xml数据的解析
一 json数据 1一条json就像一个对象,也想像OC中的数组,且内嵌了很多键值对字典 {"name" : "jack", "age" : ...
- ocLazyLoad angular 按需加载
ionic 框架 1.引用 index.html 加载 <script type="text/javascript" src="lib/oclazyload/ocL ...
- Evolutionary Computing: 3. Genetic Algorithm(2)
承接上一章,接着写Genetic Algorithm. 本章主要写排列表达(permutation representations) 开始先引一个具体的例子来进行表述 Outline 问题描述 排列表 ...
- Linux 系统启动过程
linux启动时我们会看到许多启动信息. Linux系统的启动过程并不是大家想象中的那么复杂,其过程可以分为5个阶段: 内核的引导. 运行init. 系统初始化. 建立终端 . 用户登录系统. 内核引 ...
- python抓取数据 常见反爬虫 情况
1.报文头信息: User-Agent Accept-Language 防盗链 上referer 随机生成不同的User-Agent构造报头 2.加抓取等待时间 每抓取一页都让它随机休息几秒,加入此 ...