Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Laali vs Bessie

Limits: 500ms, 1.5 GB

One day Raju discovered USACO and from that day he would spend all his time solving problems. Laali was jealous to see Raju putting so much effort to solve problems about Farmer John’s cow Bessie.

So Laali wrote a problem about herself and asked Raju to solve it. Raju wrote the following solution only to realize it would take him very long to get any output and Laali will be highly disappointed.

Take N and M as input
for i = 2 to 1,000,000,000,000
    if(i is equal to the smallest divisor of M and N>=i ) { //1 is not considered as a divisor
        M = M / i;
        N = N - i;
    }
Print N and M

Now given an initial N and M, help Raju so that he can solve the problem and save the world from the wrath of Laali.

Input

Input contains two numbers N and M denoting the initial values.

1 <= N,M <= 1012

Output

Output a single line containing the final values of N and M.

Samples

InputOutput
10 30
0 1
InputOutput
10 10
3 1
InputOutput
9 30
4 5

Author
Discussion
Submit

Login to submit