Solution 1: 参照数学质因子的定义,大概规模能跑到800,900,就会超时
我这个方法也太暴力了。
https://blog.csdn.net/fulishafulisha/article/details/79984101
class Solution {
public int nthUglyNumber(int n) {
int count=0;
int i=1; //Ugly numbers are positive numbers
while(count<n){
if(help(i,2)) count++;
i++;
}
return i-1;
}
public boolean help(int i,int k){
while(k<=i){
if(i == k){
return true;
}
else if(i%k == 0){
i = i/k;
}
else{
k++;
if(k>5)return false;
}
}
return true;
}
}