//set.count()
//queue
#include<iostream>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
#define ll long long
priority_queue<ll,vector<ll>,greater<ll> > que;
set<ll> st;
int q[]={2,3,5};
int main(){
que.push(1);
st.insert(1);
int cnt=0;
while(1){
ll a=que.top();
que.pop();
cnt++;
if(cnt==1500){
printf("The 1500'th ugly number is %lld.\n",a);
break;
}
for(int i=0;i<3;i++){
ll b=a*q[i];
if(!st.count(b)){
st.insert(b);
que.push(b);
}
}
}
return 0;
}
UVA - 136
最新推荐文章于 2020-11-07 20:39:09 发布