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. KVC与KVO

    KVC:键值编码(Key-Value-Coding),是一个非正式的Protocol,提供一种机制间接访问对象的属性,是路径访问的规范: KVO:键值观察 (Key-Value-Observe),是基 ...

  2. macaca运行报错之chrome-driver问题处理,关闭 Chrome 的自动更新

    由于chrome浏览器自动更新,导致 macaca运行报错,重新安装和更新chrome-driver 之后,还需要把chrome浏览器降级到50版本: 但是chrome会自动更新,所以需要禁止.找到这 ...

  3. js之oop <二> 对象属性

    js中对象属性可以动态添加和删除.删除对象属性用delete关键字. function obj(){ } var oo = new obj(); oo.a = "a"; oo.b ...

  4. Monkey 使用aapt查看apk包名

    使用aapt    //aapt是sdk自带的一个工具,在sdk\builds-tools\目录下1.以ES文件浏览器为例,命令行中切换到aapt.exe目录执行:aapt dump badging ...

  5. MFC编程入门之八(对话框:创建对话框类和添加控件变量)

    创建好对话框资源后要做的就是生成对话框类了.生成对话框类主要包括新建对话框类.添加控件变量和控件的消息处理函数. 例程Addition是基于对话框的程序,所以程序自动创建了对话框模板IDD_ADDIT ...

  6. Nbimer族助手 部分控件不能用的解决方法(转)

    用户提出的问题现象: 我两天笔记本安装的都是win7 SP1系统,一台为64为一台为32位,网络环境是移动宽带通过D-Link路由器实现无线局域网,DHPC自动分配IP地址.每次打开IE或者Chrom ...

  7. 主成分分析(PCA)核心思想

    参考链接:http://pinkyjie.com/2011/02/24/covariance-pca/ PCA的本质其实就是对角化协方差矩阵. PCA就是将高维的数据通过线性变换投影到低维空间上去,但 ...

  8. python3 字符串相关函数

    python版本 3.5 #Author by Liguangbo#_*_ coding:utf-8 _*_str="i like study python, welcome to my p ...

  9. CentOS 下 rpm包与 yum 安装与卸载

    rpm包的安装:      1.安装一个包 # rpm -ivh 2.升级一个包 # rpm -Uvh 3.移走一个包 # rpm -e 4.安装参数 --force 即使覆盖属于其它包的文件也强迫安 ...

  10. Codeforces Round #371 (Div. 2) C. Sonya and Queries

    题目链接 分析:01trie树,很容易就看出来了,也没什么好说的.WA了一发是因为没有看见如果数字位数大于01序列的时候01序列也要补全0.我没有晚上爬起来打,白天发现过的人极多. /******** ...