文章标题

来源:互联网 发布:淘宝上的天王表是正品 编辑:程序博客网 时间:2024/06/16 14:53

Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.

Note that 1 is typically treated as an ugly number.

题目给出丑数的定义:质因子中只包含2、3、5的正整数,判定一个数是否是丑数。easy级别,使用三个循环不断除数,直到为1。

var isUgly = function(num) {       var factorArr = [2,3,5];       for(var i=0; i<factorArr.length; ++i){            while(num !== 1){                if(num%factorArr[i] === 0){                    num /= factorArr[i];                }else{                    break;                }            }       }       return num===1; };
0 0
原创粉丝点击