Cannot understand solution

Can somebody please explain how this code is working?

Problem Link → KBIGNUMB Problem - CodeChef

Solution Link → CodeChef: Practical coding for everyone

Won’t work here because N \leq 10^{12}.

The code is working, but I cannot understand how, pls explain if you know