粤11选5任选6投注技巧:leetcode-Ugly Number

体彩赛车购买技巧 www.xyaad.icu 3/8/2017來源:ASP.NET技巧人氣:12202

Question:

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.

Solution:

class Solution { public: bool isUgly(int num) { if(num == 0){ return false; } while(num != 1){ if(num %2 != 0 && num %3 != 0 && num % 5 != 0){ return false; } if(num%2 == 0){ num /= 2; } if(num%3 == 0){ num /= 3; } if(num%5 == 0){ num /= 5; } } return true; } };

總結:

注意while判斷條件是num!=1,而不是 num != 0



时时彩博e百 21点游戏下载中文版 北京pk10官网 七乐彩免费缩水软件 最新3d技巧 三公游戏安卓版 江西老时时 排列三组选五码多少钱 三公棋牌游戏可提现 七星彩预测最准号码体彩 三公怎么玩 pk10高手教你看走势图 幸运飞艇电脑版本计划 大赢家90足球即时比分 pk10计划软件手机免费软件下载 抢庄牌九平台官网