문제 링크 : Ugly Number
/**
* @param {number} n
* @return {boolean}
*/
var isUgly = function(n) {
if(n === 1) return true
if(n < 1) return false
const divisors = [];
for(let i = 1 ; i <= Math.sqrt(n) ; i++){
if(n % i === 0) {
divisors.push(i);
if(n / i != i) divisors.push(n / i);
}
}
for(let i=0; i<divisors.length; i++) {
const el = divisors[i]
if(el === 1) continue;
if(el%2 !== 0 && el%3 !== 0 && el%5 !== 0) return false
}
return true
};
/**
* @param {number} n
* @return {boolean}
*/
var isUgly = function(n) {
if (n <= 0) {
return false;
}
while (n % 2 === 0) {
n /= 2;
}
while (n % 3 === 0) {
n /= 3;
}
while (n % 5 === 0) {
n /= 5;
}
return n === 1;
};