Number Theoretic Transform

View as PDF

Submit solution

Points: 12
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem type

Angie really enjoys studying number theory, and because she enjoys studying it so much, she created her own number theoretic function - which she aptly named the Number Theoretic Transform. She begins with two odd primes p and q (let's call their product N). She then chooses another odd number e and then computes (p+q)e and (pq)e modulo N (let's call these c1 and c2).

Lately, Angie has been having so much fun computing c1 and c2 that she lost track of her choice of p and q (which made her a bit sad). The first time this happened, she just picked new numbers and started again. However, after it kept happening throughout the day (a total of T times), she got frustrated and would now like to recover her original choices of p and q.

Given T separate instances of N, e, c1, and c2, can you help her recover her choice of p and q in each instance?

Constraints

1T100

3p,q1018 (Notably, pq=N1018 as well)

1e1018

0c1,c2<N

e is odd.

p and q are prime.

Input Specification

The first line of input contains a single integer, T.

Then, T instances of the problem follow. Each line contains the integers N, e, c1, and c2 for that instance.

Output Specification

For each instance, output p and q in increasing order on its own line, separated by spaces.

Sample Input

Copy
1
1073 91 452 563

Sample Output

Copy
29 37

Comments

There are no comments at the moment.