#include <queue>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#define ll long long
using namespace std;
int a[3]={2,3,5};
int main() {
priority_queue<ll ,vector<ll>, greater<ll> > pq;
set<ll> s;
pq.push(1);
s.insert(1);
for(int i=1;;i++) {
if(1500==i) {
printf("The 1500'th ugly number is %lld.\n",pq.top());
break;
}
else {
ll t=pq.top();pq.pop();
for(int j=0;j<3;j++) {
ll num=a[j]*t;
if(!s.count(num)) {
s.insert(num);
pq.push(num);
}
}
}
}
return 0;
}
uva 136 120页
最新推荐文章于 2019-04-29 13:34:38 发布