Smart Number 2

Sort by

recency

|

38 Discussions

|

  • + 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)

  • + 0 comments

    I have been stuck in this question for almost 2-3 hours then i realized that i should change the lanuage (c++) to another language then i tried (java7) and i succed.. You dont have to change more then 1 line..

  • + 0 comments

    Doesn't work in ruby, no initial solution.

  • + 0 comments

    def is_smart_number(num):

    val = int(math.sqrt(num))
    if **num == int(math.pow(val , 2))**:
        return True
    return False
    
  • + 1 comment

    Only square numbers have odd factors.

    • + 0 comments

      Thank you. I hate these small math trivia questions. I just dont really know enough fact, starting with what a factor is, so I struggle to make observations that could elad me to a solution. I dont really know where should i be learning these...