Do It Wrong, Get It Right
| 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.
|
| 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");
}
;
}
嗨,中村。
随机推荐
- js函数式编程
最近在看朴灵的<深入浅出nodejs>其中讲到函数式编程.理解记录下 高阶函数 比较常见,即将函数作为参数,或是将函数作为返回值得函数. 如ECMAScript5中提供的一些数组方法 fo ...
- Less入门到上手——前端开发利器<二>深入了解
接着昨天的继续... ... 4.嵌套: HTML部分 <table> <tr> <th colspan="3">测试列表标题</th&g ...
- velocity常用语句速查表
velocity常用语句 * 变量定义 #set($directoryRoot = "www" ) * #if($!list.size() != 0) //判断list不为空 #f ...
- 【转载】协同过滤 & Spark机器学习实战
因为协同过滤内容比较多,就新开一篇文章啦~~ 聚类和线性回归的实战,可以看:http://www.cnblogs.com/charlesblc/p/6159187.html 协同过滤实战,仍然参考:h ...
- Deep Learning 17:DBN的学习_读论文“A fast learning algorithm for deep belief nets”的总结
1.论文“A fast learning algorithm for deep belief nets”的“explaining away”现象的解释: 见:Explaining Away的简单理解 ...
- ffmpeg从AVFrame取出yuv数据到保存到char*中
ffmpeg从AVFrame取出yuv数据到保存到char*中 很多人一直不知道怎么利用ffmpeg从AVFrame取出yuv数据到保存到char*中,下面代码将yuv420p和yuv422p的数 ...
- mysql数据库与oracle数据库的切换
1.从mysql数据库中导出ambition(数据库名)结构和数据的ambition.sql文件. 2.将ambition.sql用Power Designer转换成mysql数据模型. 给模型起个名 ...
- zoj 1203 Swordfish prim算法
#include "stdio.h". #include <iostream> #include<math.h> using namespace std; ...
- 错误信息:System.Resources.MissingManifestResourceException: 未能找到任何适合于指定的区域或非特定区域性的资源。请确保在编译时已将“****.****.Resource.resources”正确嵌入或链接到程序集"****",或者确保所有需要的附属程序集都可加载并已进行了完全签名
在网上搜索了N久都没看到几篇解决的文章,最后在不懈的努力下终于解决了,所以决定写下解决方法方便以后遇到同样问题的朋友: 其实这个错误的主要问题就是没有找到需要的资源文件(该文件为Resources.r ...
- APIO2015 酱油记
Day 0 昨天CTSC才比完,当然是要浪啦! 于是浪了一天...午饭都没吃... 晚饭...貌似也没吃... 晚上的时候觉得这样子浪不太好,还是要认真一下,打开bzoj,弃疗了...还是浪吧... ...

