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");
}
;
}
嗨,中村。
随机推荐
- 剑指offer一:二维数组中的查找
题目: 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 思路: 这是一个顺序二维 ...
- 学习mongo系列(十)MongoDB 备份(mongodump)与恢复(mongorerstore) 监控(mongostat mongotop)
一.备份 在Mongodb中我们使用mongodump命令来备份MongoDB数据.该命令可以导出所有数据到指定目录中. mongodump命令可以通过参数指定导出的数据量级转存的服务器. mongo ...
- Python简单时间日期处理
import datetime #日期初始化: d1 = datetime.datetime(2005, 2, 16) d2 = datetime.datetime(2004, 12, 31) #日期 ...
- Cube Mapping
Cube map技术说到底就是用一个虚拟的立方体(cube)包围住物体,眼睛到物体某处的向量eyevec经过反射(以该处的法线为对称轴),反射向量reflectvec射到立方体上,就在该立方体上获得一 ...
- SSH2 框架下的分页
1.设计分页实体(pageBean) 这里我显示的是3-12页的方式: package cn.itcast.oa.domain; import java.util.List; /** * 封装分页信息 ...
- node.js基础 1之简单的nodejs模块
模块流程: 创建模块->导出模块->加载模块->使用模块 ndoejs主要就是把项目变成模块化在管理 实现一个模块的调用,编写student.js.teacher.js.klass. ...
- vue学习笔记之v-for与-repeat
今天看到一个v-repeat的例子 <body> <ul id="tags"> <li v-repeat="tags"> { ...
- 学习Django
1.安装 命令:pip install Django 安装慢且有异常:HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed ...
- 拓扑编号 vijos1790
题意就是拓扑排序,要求1的序号尽可能小,然后2的序号尽可能小,3,4... 一开始很容易想到直接贪心,每次选一个入度为0的点,如果有多个,就选编号最小的那个,但是很容易找到反例. 看了下题解,应该是反 ...
- Solr整合中文分词组件IKAnalyzer
我用的Solr是4.10版本, 在csdn下载这个版本的IKAnalyzer:IK Analyzer 2012FF_hf1.zip 解压后目录如下: (1)这里还用solr自带的example实验分词 ...

