题目描述
Alan233's company deployed an RSA encryption system for all employees, but the security department, cutting corners, decided to let all employees share the same modulus N, assigning only different (ei,di) key pairs.
Employee P received their own key (e,d) and somehow managed to hack into the company's system. While everyone was shocked, P explained nonchalantly: "I factored N."
Now, play the role of P and reproduce this attack. Given T test cases, factor N for each case and output p and q.
Note that the basic RSA workflow is as follows:
- Pick two distinct large primes p and q, and compute the modulus N=p×q;
- Compute Euler's totient function φ(N)=(p−1)×(q−1);
- Choose e coprime to φ(N) as the public exponent;
- Compute d satisfying e×d≡1(modφ(N)) as the private exponent;
- (N,e) is the public key and (N,d) is the private key. Encryption computes c=memodN, and decryption computes m=cdmodN.
Formally, you're given N,e,d satifying the above condition, you need to find out the value of p and q.
输入格式
The first line contains an integer T (1≤T≤10). The next T lines each contain three integers N,e,d(15≤N<2256, 1<e,d<φ(N), N=p×q (p,q are primes), e×d≡1(modφ(N)), and 3≤p<q<2128).
输出格式
For each test case, output one line containing two integers p,q such that p×q=N and p<q.
样例输入 #1
3
15 3 3
25777 3 16971
1005973 5 602381
样例输出 #1
3 5
149 173
997 1009