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. (淘宝无限适配)手机端rem布局详解(转载非原创)

    从网易与淘宝的font-size思考前端设计稿与工作流 本文结合自己对网易与淘宝移动端首页html元素上的font-size这个属性的思考与学习,讨论html5设计稿尺寸以及前端与设计之间协作流程的问 ...

  2. JMeter结果分析

  3. CSS使用总结

    1.visibility和display的区别: visibility:visible; 显示visibility:hidden; 隐藏,但是保留元素所占的空间display:block;       ...

  4. Pycharm使用问题# 快捷键设置

    Pycharm内部设置也已经变得非常复杂,此处说明我改变字体大小的快捷键设置. 在Settings中找到Keymap一项,默认显示会展开Editor Actions一项: 在里面分别找到Decreas ...

  5. hdu 5358 First One

    题目链接:hdu 5358 思路不难理解,就是个尺取法而已,floor(log2X) + 1 就是求 X 的二进制表示的位数,对于题目来说这个值最多只是 30+,从这里入手开始枚举,运用尺取法可以达到 ...

  6. Head First 设计模式--2 观察者模式 解耦

    观察者模式定义了对象之间一对多的依赖,这样依赖,当一个对象改变状态时,它的所有依赖者都会收到通知并自动更新. 假如有这么一个项目,监控每天的天气状况WeatherData(温度,湿度,气压).有布告板 ...

  7. 【更新】【封装必备】封装辅助 - 清理&优化工具 For Win7(IT天空会员专版)

    https://www.itsk.com/thread-353560-1-4.html nqawen 发表于 2015-7-9 17:26:37   本帖最后由 Amz 于 2015-11-25 10 ...

  8. Hbase WAL线程模型源码分析

    版权声明:本文由熊训德原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/257 来源:腾云阁 https://www.qclo ...

  9. preload pic

    http://www.farinspace.com/jquery-image-preload-plugin/

  10. ios基础篇(十二)——UINavgationController的使用(三)ToolBar

    UIToolBar存在于UINavigationController导航栏控制器中,而且默认被隐藏:设置UINavigationController的toolbarHidden属性可显示UIToolB ...