博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 10673 Play with Floor and Ceil
阅读量:6122 次
发布时间:2019-06-21

本文共 2218 字,大约阅读时间需要 7 分钟。

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;

同理。

1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 typedef long long LL; 8 9 LL Ex_GCD(LL a,LL b,LL &x,LL& y)10 {11 if(b==0)12 {13 x=1;14 y=0;15 return a;16 }17 LL g=Ex_GCD(b,a%b,x,y);18 LL hxl=x-(a/b)*y;19 x=y;20 y=hxl;21 return g;22 }23 int main()24 {25 LL T;26 LL a,b,c,g,x,y,n,m;27 scanf("%d",&T);28 while(T--)29 {30 scanf("%lld %lld",&n,&m);31 a = (LL)floor(n/(double)m);/**向下取整floor(1.999) = 1 **/32 b = (LL)ceil(n/(double)m);33 c = n;34 g = Ex_GCD(a,b,x,y);35 36 x=x*(c/g);37 b=b/g;38 x=x%b;39 while(x<0) x=x+b;40 c=c/g;41 y=(c-x*a)/b;42 printf("%lld %lld\n",x,y);43 }44 return 0;45 }

 

 

转载于:https://www.cnblogs.com/tom987690183/p/3746404.html

你可能感兴趣的文章
teamviewer 卸载干净
查看>>
多线程设计模式
查看>>
解读自定义UICollectionViewLayout--感动了我自己
查看>>
SqlServer作业指定目标服务器
查看>>
UnrealEngine4.5 BluePrint初始化中遇到编译警告的解决办法
查看>>
User implements HttpSessionBindingListener
查看>>
抽象工厂方法
查看>>
ubuntu apt-get 安装 lnmp
查看>>
焊盘 往同一个方向增加 固定的长度方法 总结
查看>>
eclipse的maven、Scala环境搭建
查看>>
架构师之路(一)- 什么是软件架构
查看>>
jquery的冒泡和默认行为
查看>>
USACO 土地购买
查看>>
【原创】远景能源面试--一面
查看>>
B1010.一元多项式求导(25)
查看>>
10、程序员和编译器之间的关系
查看>>
前端学习之正则表达式
查看>>
配置 RAILS FOR JRUBY1.7.4
查看>>
AndroidStudio中导入SlidingMenu报错解决方案
查看>>
修改GRUB2背景图片
查看>>