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");
}
;
}
嗨,中村。
随机推荐
- Fact表的星型结构
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 第一课 python的几种环境配置
第一种,pythom+eclipse+pydev 这种安装方式比较简单,网上教程比较多,需要注意的是安装eclipse前需要安装jdk.具体过程不再啰嗦了.下面主要讲讲在64位系统下安装numpy,s ...
- 《BI那点儿事》数据流转换——逆透视转换
逆透视转换将来自单个记录中多个列的值扩展为单个列中具有同样值的多个记录,使得非规范的数据集成为较规范的版本.例如,每个客户在列出客户名的数据集中各占一行,在该行的各列中显示购买的产品和数量.逆透视转换 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- 解决 scroll() position:fixed 抖动、导航菜单固定头部(底部)跟随屏幕滚动
一.导航栏或者页脚正常情况下固定在页面的相应位置,当页面滚动后,导航栏或者页脚固定在页面的顶部或者底部的情景 一般就是将该块的代码样式的position设置为fixed.固定在顶部的话,将top设置为 ...
- hdu2243考研路茫茫——单词情结(ac+二分矩阵)
链接 跟2778差不多,解决了那道题这道也不成问题如果做过基本的矩阵问题. 数比较大,需要用unsigned longlong 就不需要mod了 溢出就相当于取余 #include <iostr ...
- 【matlab】膨胀
clear all;close all; BW=zeros(9,10); BW(4:6,4:7) =1 imshow(BW) hold on SE=strel('square',3) BW2=imdi ...
- Cryptopp iOS 使用 RSA加密解密和签名验证签名
Cryptopp 是一个c++写的功能完善的密码学工具,类似于openssl 官网:https://www.cryptopp.com 以下主要演示Cryptopp 在iOS上的RSA加密解密签名与验证 ...
- c.BIO连接器与NIO连接器的对比
前面两节,我们分别看了BIO和NIO的两种模式Tomcat的实现方式. BIO的方式,就是传统的一线程,一请求的模式,也就是说,当同时又1000个请求过来,如果Tomcat设置了最大Accept线程数 ...
- table数据表格添加checkbox进行数据进行两个表格左右移动。
<table class="table table-hover table-striped table-condensed newDateList"> <thea ...

