263.[圖解]Ugly Number

1.題目描述 
來源:LeetCode

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.

寫一個 function 判斷一個給入的數是否為 “Ugly number”。若一個正整數的質因數只包含 2、3 或 5 的話為”Ugly number”,其他則否。但 1 須被判定為 “Ugly number”。

2.題目解析
一開始看到要數字被質因數來除=>想到要用數字先取有哪些質因數,然後再判斷這質因數是否有2、3、5。
但後來想想不對,因為取質因數,數字會很大。
後來再看一次題目,只需要2、3、5這三個數字來判斷。
所以就想到數字被2除、數字被3除、數字被5除,如果可以除盡,最後數字為1就是正確答案。

3.畫流程圖

4.程式碼

5.上傳LeetCode的結果

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.