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.


For a given fraction b/n, your task is to find all of the values a and m, where a ≥ 0 and m > 0, for which 

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");
     }
   ;
 }

嗨,中村。

随机推荐

  1. Javascript学习笔记:对象的属性类型

    在ECMAScript中有两种属性:数据属性和访问器属性 1.数据属性 configurable:表示能否通过delete删除属性从而重新定义属性:或者能否修改属性的特性:或者能否把属性修改为访问器属 ...

  2. [资源] Open source packages on SLAM

    OpenSLAM http://openslam.org/ Most main stream open source slam resource can be found on OpenSLAM, w ...

  3. (原创)Windows和Linux间共享文件

    方法一: Windows创建目录sharedir,修改共享属性,对everyone开放读写权限. Linux下运行命令:# mount -t cifs //192.168.8.55/sharedir ...

  4. spring+mongo

    一.程序结构

  5. TOSHIBA TEC EXT Printer Z-Mode

    Z-Mode functionality automatically converts the Zebra data stream into a TOSHIBA data stream (TPCL). ...

  6. 工作中使用的html5和css3 新特性

    1.placeholder <input type="text" placeholder="请输入手机号码" class="phone" ...

  7. Copy List with Random Pointer [LeetCode]

    A linked list is given such that each node contains an additional random pointer which could point t ...

  8. springmvc自定义日期编辑器

    1.控制器 @Controller public class MyController { // 处理器方法 @RequestMapping(value = "/first.do" ...

  9. SAP NWBC for HTML and Desktop configuration steps[From sdn]

    Summary :- This dcoumnenst conatin the information about requirement , hardware , configuration step ...

  10. 转载-Web API 入门

    An Introduction to ASP.NET Web API 目前感觉最好的Web API入门教程 HTTP状态码 Web API 强势入门指南 Install Mongodb Getting ...