// language C with STL(C++)
// 剑指49
// https://leetcode-cn.com/problems/chou-shu-lcof/
class Solution {
public:
int minpositon(int a, int b,int c){
if(b<a)
a = b;
if(c<a)
a = c;
return a;
}
int nthUglyNumber(int n) {
int dp[n];
dp[0] = 1;
int p2 = 0, p3 = 0, p5 =0;
int i = 1;
while(i<n){
dp[i] = minpositon(dp[p2] *2, dp[p3] *3, dp[p5] *5);
while(dp[p2]*2 <= dp[i]) p2++;
while(dp[p3]*3 <= dp[i]) p3++;
while(dp[p5]*5 <= dp[i]) p5++;
i++;
}
return dp[n-1];
}
};