Factorization
Time limit3sMemory limit512 MB
Given a prime p and residues a0, a1, find b0, b1 in [0, p-1] with b0*b1 = a0 and b0+b1 = a1 mod p, or report none.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Binary search, Implementation
- Solved
- No attempts yet
Problem
Integer factorization plays an important role in many cryptographic systems. It asks, for a given positive composite number , to find two positive integers and such that and . It is a well-known NP-intermediate candidate, though, and no algorithm solves it in polynomial time yet.
Taylor, a number theorist, made another factorization problem as follows.
Given a prime number and two integers , find two integers such that and .
"This factoring is way cooler, in that it can be computed efficiently," Taylor said. Now he invites you to enjoy this new variant of factorization.
Input
The first line contains an integer , the number of test cases. Each test case takes one line containing three non-negative integers separated by a single space.
Output
For each test case, output one line containing and in ascending order separated by a single space if and satisfy the two equations. If there are multiple solutions, you may output any of them. If there is no solution, output .
Constraints
- and is prime.
- .