Fork me on GitHub

LeetCode之263. Ugly Number

-------------------------------------------------------------

 

如果一个数的质因子只包括2,3,5,那么这个数n可以表示为:
n=2x+3y+5z

 

AC代码:

import java.math.BigInteger;

public class Solution {
    
    public boolean isUgly(int n) {
       if(n<1) return false;
       while(n%2==0) n/=2;
       while(n%3==0) n/=3;
       while(n%5==0) n/=5;
       return n==1;
    }
    
}

 

题目来源: https://leetcode.com/problems/ugly-number/

posted @ 2016-10-27 11:39  CC11001100  阅读(240)  评论(0编辑  收藏  举报