Guess the number (March Cook off 2021)

In this question,
when I precompute all those value whose no of factor is odd.
When I submit this It give me wrong answer.

Ther only difference is instead of precomputing i directly assign the value

when I submit this solution It give me correct answer.

Why this happen any one give me reason…