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. C#中静态与非静态方法比较

    C#静态方法与非静态方法的区别不仅仅是概念上的,那么他们有什么具体的区别呢?让我们通过本文向你做一下解析. C#的类中可以包含两种方法:C#静态方法与非静态方法.那么他们的定义有什么不同呢?他们在使用 ...

  2. 《BI那点儿事》数据仓库建模:星型模式、雪片模式

    数据仓库建模 — 星型模式Example of Star Schema 数据仓库建模 — 雪片模式Example of Snowflake Schema 节省存储空间 一定程度上的范式 星形 vs.雪 ...

  3. (转)PowerDesigner提示Existence of index、key、reference错误

    建立一个表后,为何检测出现Existence of index的警告    A table should contain at least one column, one index, one key ...

  4. cxf的soap风格+spirng4+maven 客户端

    上篇博客介绍了,cxf的soap风格的服务端,现在我们写客户端来调用 1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...

  5. SSH框架的配置

    ^_^阅读本文前请先浏览 : http://www.cnblogs.com/LiJinfu/p/5842890.html 步骤 : 一.编写web.xml配置文件 该文件路径在项目文件下的WebCon ...

  6. PHP 扩展开发小结

    1. 变量操作(常量) 设置变量 ZVAL_*系列函数; 例: zval t; ZVAL_STRING(t,"10",2); 获取变量 Z_* 系列函数 获取变量指针 Z_*_P ...

  7. JavaScript类型判断

    几种方法:typeof,instanceof,Object.prototype.toString,constructor,duck type ES6引入了一种新的原始数据类型Symbol,表示独一无二 ...

  8. 删除桌面IE图标

    B416D21B-3B22-B6D4-BBD3-BBD452DB3D5B HKEY_USERS\S-1-5-21-3567631753-1637826720-2857290141-500\Softwa ...

  9. 【USB多路电源】layout

    USB多路电源的layout 图:第一次layout 缺点: 1.散,空间利用率不高: 2.不整齐: 3.没有符合左上进,右下出(当然也不必墨守): 4.输出排针没有放到最边上: 5.信号流向问题 6 ...

  10. 把字典的key value 拼接成字符串加上签名加密

    - (NSString *)getSianKeyWithDic:(NSDictionary *)dic { //按字典排序 NSArray* arr = [dic allKeys]; arr = [a ...