[LeetCode] Ugly Number

No matter what language you use on the OJ, you may refer to Stefan's post for a solution. The C++ is rewritten below, just really concise.

1 class Solution {
2 public:
3     bool isUgly(int num) {
4         for (int i = 2; i < 6 && num; i++)
5             while (!(num % i)) num /= i;
6         return num == 1;
7     }
8 };

Note that i = 4 will simply be skipped after we try to divide by 2 as much as possible.

原文地址:https://www.cnblogs.com/jcliBlogger/p/4742618.html