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"); } ; }
嗨,中村。
随机推荐
-
Navicat for mysql 破解
想用navicat for mysql 连接mysql,发现只能试用30天,感觉挺不爽的,购买的话发现价格一千多,好贵的软件. 所以想要破解一下,网上试了一些方法不行,最后找到了一种方法可以的 破解工 ...
-
C++中虚析构函数的作用
我们知道,用C++开发的时候,用来做基类的类的析构函数一般都是虚函数.可是,为什么要这样做呢?下面用一个小例子来说明: 有下面的两个类: class ClxBase { public: ...
-
jQuery核心之DOM操作的常用方法
参考jQuery官网API文档 1..attr() 获取 : ); 3.选择器与常用方法: ) .html( "new text for the third h3!" ) .en ...
-
软件测试--测试Demo
视频地址(第二课时):https://pan.baidu.com/s/1gfLVC2n 软件安装好了! 软件默认的浏览器是火狐. 如果需要IE,chrome,都在前一篇的安装包里有. 测试结果 视频里 ...
-
Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它)
在android的应用层中,涉及到很多应用框架,例如:Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架,通知机制,ActionBar框架等等. ...
-
各种效果的tab选项卡
;(function($){ $.fn.tabso=function( options ){ var opts=$.extend({},$.fn.tabso.defaults,options ); r ...
-
jQuery1.9为动态添加元素绑定事件以及获取和操作checkbox的选择属性
1.jQuery为动态添加的元素绑定事件:在1.7之后,添加了live()方法,1.9后又被移除,1.9中可用on()方法: $(function() { $('.btn').on('click', ...
-
PHPMySQL 中 pdo文件的增删改查
<?php //PDO类的增删改查 try { $pdo = new PDO("mysql:host=localhost;dbname=ooo","root&quo ...
-
一个关于自定义类型作为HashMap的key的问题
在之前的项目需要用到以自定义类型作为HashMap的key,遇到一个问题:如果修改了已经存储在HashMap中的实例,会发生什么情况呢?用一段代码来试验: import java.util.HashM ...
-
C#驱动及应用
一,使用开源客户端:StackExchange.Redis 二,使用方法: 1,获取访问redis数据库连接,代码如下. /// <summary> /// 获取访问redis数据 ...