首页 > 其他 > 详细

Ugly Number

时间:2015-12-05 17:22:54      阅读:196      评论:0      收藏:0      [点我收藏+]

https://leetcode.com/problems/ugly-number/

class Solution {
public:
    bool isUgly(int num) {
        if(num<=0)
            return false;
        if(num==1)
            return true;
        int temp=num;
        bool flag=true;
        while(temp!=1)
        {
            if(isPrime(temp,2)==true)
                temp/=2;
            else if(isPrime(temp,3)==true)
                temp/=3;
            else if(isPrime(temp,5)==true)
                temp/=5;
            else
            {
                flag=false;
                break;
            }
        }
        return flag;
        
    }
    bool isPrime(int a,int b)
    {
        if(a/b*b==a)
            return true;
        else
            return false;
    }
};

  

Ugly Number

原文:http://www.cnblogs.com/aguai1992/p/5021793.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!