Romualdych and remainders

시간 제한2초메모리 제한1024 MB

요약
각 질의 [a,b]와 나머지 r에 대해, x mod y = r을 만족하는 가장 작은 x와 적당한 y를 1 이상 2×10^18 이하에서 찾고, 불가능하면 -1 -1을 출력한다.
난이도

보통10점 중 6점

유형
수학, 정수론, 이분 탐색, 구현
정답자
아직 제출이 없습니다

문제

Old man Romualdych learned about division with remainders and it just threw him off the hinges. The thing got him all mixed up and sweating like a pig. What a sad sight he was, hoping to find some number xx in the interval \[a,b]\[a,b], that would produce the specified remainder rr when divided by some number yy. Let's face it --- Romualdych is not the sharpest tool in the shed, and even if he sinks his few remaining teeth into the task, he is not likely to cope without your help.

입력

The first line contains a single integer TT --- the number of tests in the file (1≤n≤200,0001 \le n \le 200\\,000).

Each of the following TT lines contains three integers: aa, bb --- interval bounds, and rr --- required remainder (0≤a≤b≤10180 \le a \le b \le 10^{18}, 0≤r≤10180 \le r \le 10^{18}).

출력

Print TT answers in the same order as the tests in the input file are given, one answer per line.

Each answer consists of two integers xx and yy, such that a≤x≤ba \le x \le b, 1≤y≤2⋅10181 \le y \le 2 \cdot 10^{18}, and the remainder from the division of xx by yy equals rr. If there are several possible answers that fit all the requirements, choose any answer with the minimal xx. If there are no possible answers, print two integers: x=−1x = -1 and y=−1y = -1.

힌트

In the first test, 6 is divided by 3, and the remainder is indeed 0. Since 6 is the smallest number in the interval \[6,8]\[6,8], this is the correct answer. Instead, the following answer can be printed too: x=6x = 6 and y=2y = 2 (minimizing yy is not required), while the answer x=8x = 8 and y=4y = 4 cannot be printed, because its xx is not minimal.

In the second test, there are no answers, since it is impossible to get a remainder of 10 for xx in the interval [3,5] regardless of the yy it is divided by.

예제1

  1. 예제 1

    입력
    2
    6 8 0
    3 5 10
    
    예상 출력
    6 3
    -1 -1