1. 程式人生 > >51Nod1010 只包含因子2 3 5的數(打表+ lower_bound)

51Nod1010 只包含因子2 3 5的數(打表+ lower_bound)

 lower_bound這個函式挺好用的。

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const ll N=1e18+100;
ll s[100000];
int m=0;
void init()
{
	ll i,j,k;
	for(i=1;i<N;i=i*2)
		for(j=1;j*i<N;j=j*3)
			for(k=1;k*i*j<N;k=k*5)
				s[m++]=i*j*k;
}
int main()
{	
	init();
	int T;
	cin>>T;	
	sort(s,s+m);	
	while(T--)
	{
		ll a;
		cin>>a;
		cout<<*lower_bound(s+1,s+m,a)<<endl;
	}
	return 0; 
}