输入格式
输出格式
输入
输出
The 1500'th ugly number is <number>.
#include<bits/stdc++.h>
#define read() freopen("input.txt","r",stdin);
#define write() freopen("output.txt","w",stdout);
using namespace std;
typedef long long ll;
priority_queue<ll,vector<ll>,greater<ll> >pq;
set<ll>s;
int ccoff[] = {2,3,5};
int main()
{
pq.push(1);s.insert(1);
for( int i=1; ; i++ ){
ll hea=pq.top();pq.pop();
if(i==1500){
printf("The 1500'th ugly number is %d.\n",hea);break;
}
for( int j=0; j<3; j++ ){
ll num = hea*ccoff[j];
if(!s.count(num)){ pq.push(num);s.insert(num);}
}
}
return 0;
}