poj 1338 Ugly Numbers
#include <iostream>
using namespace std;
int factor[3]={2,3,5},prime[1510]={1};
int start[3];
int main()
{
int i,j,min,n;
for(i=1;i<1510;i++)
{
min=2147483647;
for(j=0;j<3;j++)
if(prime[start[j]]*factor[j]<min)
min=prime[start[j]]*factor[j];
prime[i]=min;
for(j=0;j<3;j++)
if(prime[start[j]]*factor[j]==min)
start[j]++;
}
while(scanf("%d",&n)&&n)
{
printf("%d\n",prime[n-1]);
}
return 0;
}