Problem A
Play with Floor and Ceil
Input: standard input
Output: standard output
Time Limit: 1 second

Theorem

For any two integers x and k there exists two more integers p and q such that:

It’s a fairly easy task to prove this theorem, so we’d not ask you to do that. We’d ask for something even easier! Given the values of x and k, you’d only need to find integers p and q that satisfies the given equation.

Input

The first line of the input contains an integer, T (1≤T≤1000) that gives you the number of test cases. In each of the following T lines you’d be given two positive integers x and k. You can safely assume that x and k will always be less than 108.

Output

For each of the test cases print two integers: p and q in one line. These two integers are to be separated by a single space. If there are multiple pairs of p and q that satisfy the equation, any one would do. But to help us keep our task simple, please make sure that the values,  and fit in a 64 bit signed integer.

Sample Input                              Output for Sample Input

3

5 2

40 2

24444 6

1 1

1 1

0 6


Problem setter: Monirul Hasan, Member of Elite Problemsetters' Panel

Special Thanks: Shahriar Manzoor, Member of Elite Problemsetters' Panel

知道floor和ceil 就行。

floor向下取整 floor(1.9999) = 1;

同理。

 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef long long LL; LL Ex_GCD(LL a,LL b,LL &x,LL& y)
{
if(b==)
{
x=;
y=;
return a;
}
LL g=Ex_GCD(b,a%b,x,y);
LL hxl=x-(a/b)*y;
x=y;
y=hxl;
return g;
}
int main()
{
LL T;
LL a,b,c,g,x,y,n,m;
scanf("%d",&T);
while(T--)
{
scanf("%lld %lld",&n,&m);
a = (LL)floor(n/(double)m);/**向下取整floor(1.999) = 1 **/
b = (LL)ceil(n/(double)m);
c = n;
g = Ex_GCD(a,b,x,y); x=x*(c/g);
b=b/g;
x=x%b;
while(x<) x=x+b;
c=c/g;
y=(c-x*a)/b;
printf("%lld %lld\n",x,y);
}
return ;
}

uva 10673 Play with Floor and Ceil的更多相关文章

  1. php四舍五入函数(floor、ceil、round与intval)

    原文链接:php四舍五入函数(floor.ceil.round与intval) PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法 ...

  2. Number(),parseInt(),parseFloat(),Math.round(),Math.floor(),Math.ceil()对比横评

    首先,这些处理方法可分为三类. 1,只用来处理数字取整问题的:Math.round(),Math.floor(),Math.ceil(): 2,专门用于把字符串转化成数值:parseInt(),par ...

  3. POJ1061:青蛙的约会+POJ2115C Looooops+UVA10673Play with Floor and Ceil(扩展欧几里得)

    http://poj.org/problem?id=1061 第一遍的写法: #include <iostream> #include <stdio.h> #include & ...

  4. Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明

    Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明 FLOOR——对给定的数字取整数位SQL> select floor(2345.67) from dua ...

  5. 问题:oracle floor;结果:Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明

    Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明 (2011-04-06 16:10:35) 转载▼ 标签: 谈 分类: 渐行渐远 FLOOR——对给定的数字取 ...

  6. Play with Floor and Ceil UVA - 10673(拓展欧几里得)

    因为我现在还不会用这个...emm...蒟蒻...只看了 从来没用过....所以切一道水题...练一下... 人家讲的很好  https://blog.csdn.net/u012860428/arti ...

  7. Java Math floor round ceil 函数

    public final class Math extends Object public static double floor(double a) public static long round ...

  8. JavaScript中Math--random()/floor()/round()/ceil()

    Math.random():返回0-1之间的任意数,不包括0和1: Math.floor(num):返回小于等于num的整数,相当于四舍五入的四舍,不五入:例子:Math.floor(1.0);Mat ...

  9. 关于Math类的round、floor、ceil三个方法

    一.Math类这三个方法的简介 1.round():取最接近的值. 对于这个方法,查看源代码,其实现如下: public static long round(double a) { if (a != ...

随机推荐

  1. Codeforce Round #226 Div2

    这次CF虽然,但是- - 第一题看了很久的题目意思额,虽然慢了点- -,但还算没出错,还学会了hack了- -,还+了100- - 第二题想了很久- -...后来发现可以暴力- -,哎 第三题本来也应 ...

  2. codevs 1206 保留两位小数

    http://codevs.cn/problem/1206/ 1206 保留两位小数  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题解  查看运行结果 ...

  3. 。。。Hibernate注解配置的注意事项。。。

    今天本来打算录视频的,突然遇到一个拦路虎,Hibernate注解配置,有一个注意点:要么都在属性上面注解配置,要么都在getXX()方法上面用注解配置,要不然就会报错: Caused by: org. ...

  4. eclipse key

    让我们按照使用频率来看看我最爱用的一些热键组合.(注:以下内容在Eclipse3.02及一上版本通过测试) . Control-Shift-T: 打开类型(Open type).如果你不是有意磨洋工, ...

  5. 重要的事情说三遍:列表 ul / ol 等是块级元素,是块级元素,块级元素

    HTML 块级元素 大多数 HTML 元素被定义为块级元素或内联元素. 编者注:“块级元素”译为 block level element,“行内元素”译为 inline element. 块级元素在浏 ...

  6. [转]Delphi多线程编程入门(一)

    最近Ken在比较系统地学习Delphi多线程编程方面的知识,在网络上查阅了很多资料.现在Ken将对这些资料进行整理和修改,以便收藏和分享.内容基本上是复制粘贴,拼拼凑凑,再加上一些修改而来.各个素材的 ...

  7. IMG图片和文字同行显示

    只要设定img标签的vertical-align CSS属性就好了,代码如下: <img src="images/untitled.png" style="widt ...

  8. 【python cookbook】【字符串与文本】8.编写多行模式的正则表达式

    问题:用正则表达式对一段文本块做匹配,但是希望在进行匹配时能够跨越多行 解决方案: 1.正则表达式添加对换行符的支持: 2.re.compile()函数一个有用的标记-re.DOTALL使得正则表达式 ...

  9. oracle sql语言模糊查询--通配符like的使用教程

    转自:http://www.cnblogs.com/tyler2000/archive/2011/04/28/oracleSql.html oracle在Where子句中,可以对datetime.ch ...

  10. html5+php实现文件的断点续传ajax异步上传

    html5+php实现文件的断点续传ajax异步上传 准备知识:断点续传,既然有断,那就应该有文件分割的过程,一段一段的传.以前文件无法分割,但随着HTML5新特性的引入,类似普通字符串.数组的分割, ...