LeetCode 264. Ugly Number II
typedef long long int _int;
class Solution {
public:
_int ugly[2000];
_int num[2000];
int nthUglyNumber(int n) {
ugly[0]=1;
int x=0,y=0,z=0;
int pos=1;
while(pos<n)
{
int a = min(2*ugly[x],min(3*ugly[y],5*ugly[z]));
if(a==2*ugly[x])
x++;
if(a==3*ugly[y])
y++;
if(a==5*ugly[z])
z++;
ugly[pos++]=a;
}
return ugly[n-1];
}
};