标签:
只包含因子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