int min(int a, int b){

return a < b ? a : b;

}

int nthUglyNumber(int n) {

int *k = (int*)malloc(sizeof(int) * n);

k[0] = 1;

if(n == 1){

return 1;

}

int index2 = 0, index3 = 0, index5 = 0;

int i = 0;

```
for(; i < n; i ++){
k[i + 1] = min(min(k[index2] * 2, k[index3] * 3), k[index5] * 5);
if(k[i + 1] == k[index2] * 2){
index2 ++;
}
if(k[i + 1] == k[index3] * 3){
index3 ++;
}
if(k[i + 1] == k[index5] * 5){
index5 ++;
}
}
return k[n - 1];
```

}