Blue Bridge Training a few lucky number

The first few lucky number
to x Planet travel visitors are sent to an integer, as a tourist numbers.
x king star has a knack, he only likes numbers 3, 5 and 7.
King provisions, if the number of visitors contains only factor: 3,5,7, you can get a prize.
Let's look at the first 10 lucky numbers are:
3,579,152,125,273,545
so the first 11 lucky numbers are: 49
Xiao Ming received a lucky number 59084709587505, he went to accept the award, when people asked him precisely this is the first of several lucky number, otherwise not receive prizes.
Xiao Ming to help you calculate, 59,084,709,587,505 are a few lucky number.
Is required to submit an integer, please do not fill out any extra content.

This question online practice a lot, I saw a pupil Gangster (%%), his idea is very good, is to build an array with 3,5,7, each time taking out upper_bound function with a set larger than before the number, while only less than the required numbers let into the set, and finally find a size on the line.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long a[3]={3,5,7};
int main()
{
	set<ll>s;
	long long x=1;
	while(1)
	{		
		
		if(x==59084709587505)
		{
			break;
		}
		for(int i=0;i<=2;i++)
		if(x*a[i]<=59084709587505)
		{
		
			s.insert((long long)x*a[i]);
		}
		x=*s.upper_bound(x);
	}
	cout<<s.size()<<endl;
	return 0;
 } 
Published 165 original articles · won praise 8 · views 2467

Guess you like

Origin blog.csdn.net/qq_45961321/article/details/105010908