201804第幾個幸運數

關聯:醜數

在這裏插入圖片描述

#include<bits/stdc++.h> 
using namespace std; 
typedef long long LL;
const LL MAX = 59084709587505;
int main()
{
	//cpu 1秒 10^8. 硬算 枚舉的話,是不現實的。
	// 提高聯想應變能力, 多做題、多看 
	//素數   
	// check  試除 
	//  生成法  篩法  set   
	int a[3]={3,5,7};
	LL head=1;
	set<LL> s;
	while(true){
		for(int i=0;i<3;i++){
			LL tt = head*a[i];	
			if(tt<=MAX){
				s.insert(tt);
			}
		}
		head = *s.upper_bound(head);
		if(head>=MAX){
			break;
		}
	}
	cout<<s.size()<<'\n';
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章