POJ 1338 Ugly Numbers G++
程序员文章站
2022-03-23 17:33:01
...
只由2、3、5组成的数叫丑数。按照习惯1也是丑数。给出n,求第n个丑数。
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
//谢谢博友文章
vector<long long> hs;
int main()
{
//cout<<pow(2,0)<<endl;
int count=1;
for(int a=0;a<35;a++)
{
for(int b=0;b<35;b++)
{
for(int c=0;c<35;c++)
{
long long t=pow(2,a)*pow(3,b)*pow(5,c);
if((t<900000000)&&(t>0))
{
hs.push_back(t);
}
}
}
}
sort(hs.begin(),hs.end());
while(1)
{
int th;
cin>>th;
if(th==0)
{
break;
}
cout<<hs[th-1]<<endl;
}
return 0;
}