v_yanushkovsky

#263 Ugly Number

Jul 24th, 2026
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.18 KB | None | 0 0
  1.     bool isUgly(int n) {
  2.         if (n <= 0) return false;
  3.  
  4.         for (int p : {2, 3, 5}) {
  5.             while (n % p == 0) n /= p;
  6.         }
  7.        
  8.         return n == 1;
  9.     }
Advertisement
Add Comment
Please, Sign In to add comment