1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <iomanip> #include <set> #include <queue> #include <stack> #include <vector> #include <map> #include <string> #include <sstream> #include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;++i) #define per(i,a,n) for(int i=n-1;i>=a;--i); #define ms(x,a) memset((x),a,sizeof((x))) #define all(x) x.begin(),x.end() #define ins(x) inserter(x,x.begin()) #define INF 0x3f3f3f3f #define eps 1e-8 #define fi first #define e 2.718281828459045235360287471352662497757247093699959574966967627724076630353 #define se second #define mp make_pair #define pb push_back #define np next_permutation #define gapline cout<<"##======================##"<<endl using namespace std; const int maxn=1e5+5;
typedef long long ll; const int coeff[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++){ ll x=pq.top();pq.pop(); if(i==1500){ cout<<"The 1500'th ugly number is "<<x<<".\n"; break; } rep(j,0,3){ ll x2=coeff[j]*x; if(!s.count(x2)) {pq.push(x2);s.insert(x2);} } } }
|