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 all two integers x and K there exists two more integers p and Q such that:
It ' s a fairly easy tasks to prove this theorem, so we ' d ' don't ask for you. 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 t He given equation.
Input
The ' The ' input contains an integer, T (1≤t≤1000) that gives your number of test cases. In each of the following T lines your ' d be given two positive integers x and K. Can safely assume that x and K would always be less than 8.
Output
For each of the test cases print two integers: p and Q at one line. These two integers are to is separated by a. If There are multiple pairs of p and Q that satisfy the equation, any one would do. But to help us keep we task simple, please make sure that the values,
and
Fit in a bit signed integer.
Classification Discussion ~ The answer is actually very simple (see Code)
Complete code:
01./*0.012s*/
.
#include <cstdio>
.
05.int main (void)
06.{
An int t, x, K; scanf ("%d", &t);
While (t--)
. { scanf ("%d%d", &x, &k);
. if (x% k)
. printf ("%d%d\n",-X, x); else
. printf ("0%d", k);
. return 0;
18.}
PS: If the problem requires p,q nonnegative, then P is-x% (x/k+1) +x/k+1
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/