Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence
1, 2, 3, 4, 5, 6, 8, 9, 10, 12, ...
typedef pair<ll, int> node_type;
int main()
{
ll result[1500];
priority_queue<node_type, vector<node_type>, greater<node_type> >Q;
Q.push(make_pair(1, 2));
int i;
for (i = 0; i < 1500; ++i) {
node_type node = Q.top();
Q.pop();
switch(node.second) {
case 2: Q.push(make_pair(node.first * 2, 2));
case 3: Q.push(make_pair(node.first * 3, 3));
case 5: Q.push(make_pair(node.first * 5, 5));
}
result[i] = node.first;
}
int n;
while (cin>>n && n) {
cout<<result[n - 1]<<endl;
}
return 0;
}