1 / 5
Dec 2014

@Lakshman, thats exactly what I did!
When g = 1 it implies m and n have no factors in common so its just m*n.
I don't understand your point, can you give me an example where g = 1 and answer is not m*n?

There is a bug in my program, its the factorization.
I am not factorizing well frowning but it is not the cause of my WA as I added 'assert g == 1' after the factorization and no error was raised, so probably my factorization is good enough(?)

PS: for primes or for numbers whose factors are primes greater than sqrt(2**31) for ex 47497, my code gives wrong output. But I think no such test cases are present in the problem as it would raise an assertion error when 'assert g == 1' is placed after factorization.

EDIT: Thanks for the reply lakshman, I deleted that code and coded it again, it got AC.

6 years later

This is completely unrelated to this problem. This is regarding your comment on the problem Just Primes2, which you solved a couple of days ago. Can you share your solution or some resource/logic/hint on how to solve using the topic you mentioned “FFT”.