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

By raida_ash · 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 contains two numbers N (1 ≤ N ≤ 1012) and M (1 ≤ M ≤ 1012) denoting the initial values.


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


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



59% Solution Ratio

NirjhorEarliest, Aug '17

Asif_AlimFastest, 0.0s

NirjhorLightest, 131 kB

mdvirusShortest, 191B


Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.