What's the logic behind this part of code?

Here is the problem:
https://codeforces.com/contest/1285/problem/C

Here are the most visible solutions with same logic used everywhere. I don’t understand why this logic is getting AC.

https://codeforces.com/contest/1285/submission/68564208

Editorial here
https://codeforces.com/blog/entry/72950

Also it’s editorial code was difficult to grasp. Can anyone explain the logic used in editorial as well? Thanks

Find all the Fctors of the number…
Ex 20-
1-20
2-10
4-5
These are the 4 possible…the Factor will both co-primes or the pair of factors with gcd one will be the answer​:slightly_smiling_face::slightly_smiling_face: