首页 > 其他 > 详细

丑数问题

时间:2016-06-12 23:03:53      阅读:179      评论:0      收藏:0      [点我收藏+]

只包含因子2,3,5的树称之为丑数  ,查找指定位置的丑数

package offer;

public class choushu {
    public static boolean isugly(int num){
        if(num<=0){
            return false;
        }
        while(num%2==0){
            num/=2;
        }
        while(num%3==0){
            num/=3;
        }
        while(num%5==0){
            num/=5;
        }
        if(num==1)
            return true;
        else 
            return false;    
    }
    public static int findugly(int index){
        int num=0;
        int num_ug=0;
        while(num_ug<index){
            ++num;
            if(isugly(num)){
                num_ug++;
                
            }
        }
        return num;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
System.out.println(findugly(7));
    }

}

 

丑数问题

原文:http://www.cnblogs.com/lucyliu/p/5578878.html

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