难度:easy

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整除,而不能被其他数字整除,则它被称为”ugly number“,1被认为是一个特殊的ugly number。

           中间部分是我自己写的,超时了,参考别人写出。用for 和while叠套,让给定数字分别被2,3,5除尽,如果最后为1,则被判定为ugly number。

leetcode 263[easy]---Ugly Number

           

           


相关文章: