LeetCode编程练习
来源:互联网 发布:java视频教程数组 编辑:程序博客网 时间:2024/06/07 01:19
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做了判断。
按照上述方法,去除对4的判断,只对2,3,5的倍数的数做处理。
阅读全文
0 0
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode 编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- AbstractQueuedSynchronizer的介绍和原理分析
- LeetCode编程练习
- Fragment知识点,一篇搞定!
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- superset 出现数据库错误
- (一)驱动开发之环境搭建
- (二)驱动模块开发过程
- 图解Android
- (三)驱动开发字符设备过程
- Springboot+mybatis 搭建并完美整合