class Solution {

public:

int nthUglyNumber(int n) {

```
if(n == 1)
return 1;
queue <unsigned int> q2;
queue <unsigned int> q3;
queue <unsigned int> q5;
int count = 1;
int next_ugly,nth_ugly;
q2.push(2);
q3.push(3);
q5.push(5);
while(count < n)
{
next_ugly = std::min(q2.front(),min(q3.front(),q5.front()));
if(next_ugly == q2.front())
{
int val = q2.front();
q2.push(val*2);
q3.push(val*3);
q5.push(val*5);
q2.pop();
}
else if(next_ugly == q3.front())
{
int val = q3.front();
q3.push(val*3);
q5.push(val*5);
q3.pop();
}
else
{
int val = q5.front();
q5.push(val*5);
q5.pop();
}
count++;
if(count == n)
nth_ugly = next_ugly;
}
return nth_ugly;
}
```

};