Problem 541
Ugly Number Check
Easy · 10 pts · Math
Problem
An ugly number is a positive integer whose only prime factors are 2, 3 and 5. The number 1 counts as ugly because it has no prime factors at all. Zero and negative numbers are never ugly. Given an integer N, decide whether it is ugly. Divide N by 2, 3 and 5 as long as it is divisible by them; N is ugly exactly when what remains is 1.
Input
A single integer N.
Output
Print YES if N is an ugly number, otherwise NO.
Constraints
-2^31 <= N <= 2^31 - 1
Example input
6
Example output
YES
Explanation
6 = 2 × 3 uses only the prime factors 2 and 3, so it is ugly and the answer is YES. A number like 14 = 2 × 7 would be NO because of the factor 7.