forked from lennylxx/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path263.c
More file actions
38 lines (31 loc) · 674 Bytes
/
263.c
File metadata and controls
38 lines (31 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
bool isUgly(int num) {
if (num <= 0) return false;
while (num > 1) {
bool flag = false;
if (num % 2 == 0) {
flag = true;
num /= 2;
}
if (num % 3 == 0) {
flag = true;
num /= 3;
}
if (num % 5 == 0) {
flag = true;
num /= 5;
}
if (!flag) return false;
}
return true;
}
int main() {
assert(isUgly(0) == false);
assert(isUgly(1) == true);
assert(isUgly(6) == true);
assert(isUgly(14) == false);
printf("all test passed.\n");
return 0;
}