Three points:
Modulo checks divisibility. If , then is divisible by .
Repeated division shrinks numbers predictably. Powers of two shrink cleanly when divided by .
Early exit saves time. If you detect failure mid-loop, return immediately instead of continuing.