We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Smart Number 2
- Discussions
Smart Number 2
Smart Number 2
Sort by
recency
|
38 Discussions
|
Please Login in order to post a comment
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)
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..
Doesn't work in ruby, no initial solution.
def is_smart_number(num):
Only square numbers have odd factors.