Advertisement
tanchukw

Untitled

Sep 14th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.21 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool isUgly(int num) {
  4.         if (!num)
  5.             return 0;
  6.         while (!(num % 2))
  7.             num /= 2;
  8.         while (!(num % 3))
  9.             num /= 3;
  10.         while (!(num % 5))
  11.             num /= 5;
  12.         return (num == 1);
  13.     }
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement