#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
using namespace std;

typedef long long LL;
const int maxn=10010;
const int N=10;

priority_queue<LL,vector<LL>,greater<LL> > pq;

int a[]={2,3,5};

int main(){
	
	set<LL> st;
	
	st.insert(1);
	pq.push(1);
	
	for(int i=1;;i++){
		
		LL x=pq.top(); pq.pop();		
		
		if(i==1500){
			
			printf("The 1500`th ugly number is %lld\n",x);
		}
		
		for(int j=0;j<3;j++){
			
			LL x2=a[j]*x;
			
			if(!st.count(x2)){
				
				st.insert(x2);
				pq.push(x2);
			}
		}
		
		
	}
	
	
	return 0;
}

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐