Can anyone help me understand the logic behind this question Coprime Conundrum Question Link
I have understood the question but am finding it difficult to understand the editorial.
The problem setters code looks simple. But I still dont get it what is happening.
It has been explained here by wannabe_khiladi.