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. postMessage

    postMessage 父页面 e.target.contentWindow.postMessage(messageData, '*'); /*******onMessage处理******/ fun ...

  2. lamp centos虚拟主机配置

    1.基于不同端口的虚拟主机配置 [root@lamp~]# vi /etc/httpd/conf/httpd.conf Listen 80      #设置监听不同的虚拟主机需要使用的端口 Liste ...

  3. 被table单元格colspan属性折磨了

    基础知识不牢固,被colspan折磨了很长时间 table里面的td使用colspan前提条件是所跨的单元格宽度必须一样,不然显示效果会是属性不起作用或直接导致表格变形,下面的例子可以看出效果 < ...

  4. windows+linux开发环境 解决laravel blade模板缓存问题

    编码环境windows10 编码IDE:phpstorm 2016.2 PHP框架:laravel5.3 + 代码运行环境:centos7 + nginx 在开发过程中,上传blade模板文件到lin ...

  5. 基于注解的Spring AOP的配置和使用--转载

    AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...

  6. java判断时间是否是今天

    SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd"); Date d1=format.parse(FHavetime ...

  7. tfs 分支

    集团-IT部张强 11:15:211.主干时刻处于稳定状态,随时可以发布.设专门人员对主干代码进行管理,普通开发人员只读. 2.为开发任务建立开发分支.常规的可以以小组为单位建立分支,较大的任务可以建 ...

  8. iOS中属性与成员变量的区别

    一.类Class中的属性property 在ios第一版中,我们为输出口同时声明了属性和底层实例变量,那时,属性是oc语言的一个新的机制,并且要求你必须声明与之对应的实例变量,例如: @interfa ...

  9. hdu----1686 Oulipo (ac自动机)

    Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  10. pagemap, from the userspace perspective

    pagemap, from the userspace perspective --------------------------------------- pagemap is a new (as ...