2题目:

   Write a program to check whether a given number is an ugly number.

      Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example,6, 8 are ugly while14 is not ugly since it includes  another prime factor7.

      Note that 1 is typically treated as an ugly number.

   编写一个程序来检查给定的数字是否是一个难看的数字。难看的数字是正数,其主要因数只有2,3,5,。例如,6,8是难看数字,14不是,因为它包含另一个侄子因子7。1通常被视为难看数字。


思路:

   就是说只要判断是不是2,3,5的倍数,如果是且不是其他质子的倍数,那这个数就是难看数。解决方案中,直接以循环除以2,3,5的方式,然后检查是否为1,但其中也对4做了判断。

LeetCode编程练习 - Ugly Number学习心得

  

   按照上述方法,去除对4的判断,只对2,3,5的倍数的数做处理。

LeetCode编程练习 - Ugly Number学习心得



相关文章:

  • 2021-06-25
  • 2021-08-04
  • 2021-11-16
  • 2021-10-03
  • 2021-04-06
  • 2021-12-11
  • 2021-06-26
  • 2021-04-24
猜你喜欢
  • 2021-06-04
  • 2021-06-15
  • 2021-09-07
  • 2021-09-26
  • 2021-05-13
  • 2021-06-05
  • 2021-11-12
相关资源
相似解决方案