Smart Number 2

  • + 0 comments

    One way to think about it: Only perfect squares have odd factors, hence if we square back val (sqrt of the original number), we should get the original number back. If we don't get the original number, it means that it wasn't a perfect square and the int(...) truncated something.

    Solution: if val**2 == num

    E.g. sqrt(2) = 1.414. Next int(1.414) = 1. Finally, 1^2 != 2 (conclusion: 'NO' - not a perfect square hence even factors) E.g. sqrt(169) = 13.0. Next int(13.0) = 13. Finally 13^2 == 169 (conclusion 'YES': perfect square hence odd factors)