UVa 10673 play with Floor and Ceil: number theory

Source: Internet
Author: User
Tags integer printf time limit

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.

3
5 2
2
24444 6
1 1
1 1
0 6

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.