1 #include
2 using namespace std;
3 typedef long long ll;
4 int main()
5 {
6 ll num=1;
7 priority_queue,greater > q;//小数优先的优先队列
8 map mp;
9 int x[3]={2,3,5},cnt=1;
10 q.push(num);
11 mp[num]++;
12 while(!q.empty())
13 {
14 num=q.top();
15 q.pop();
16 if(cnt==1500){
17 cout<<"The 1500‘th ugly number is "<"."<<endl;
18 break;
19 }
20 for(int i=0;i<3;++i){
21 ll a=num*x[i];
22 if(mp[a]==0){//对取过的丑数进行标记
23 q.push(a);
24 mp[a]++;
25 }
26 }
27 cnt++;
28 }
29 return 0;
30 }