10673 - Play with Floor and Ceil
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1614
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.
3 5 2 40 2 24444 6 |
1 1 1 1 0 6 |
分类讨论~答案其实很简单(见代码)
完整代码:
01./*0.012s*/ 02. 03.#include<cstdio> 04. 05.int main(void) 06.{ 07. int t, x, k; 08. scanf("%d", &t); 09. while (t--) 10. { 11. scanf("%d%d", &x, &k); 12. if (x % k) 13. printf("%d %d\n", -x, x); 14. else 15. printf("0 %d", k); 16. } 17. return 0; 18.}
PS:若题目要求p,q非负,则p为-x%(x/k+1)+x/k+1
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索integer
, single ask
, and
, of
, The
, You
that
menatplay floor、wipe the floor with、乐高10673、乐高10673拼装图纸、iso10673,以便于您获取更多的相关知识。