题干:

I will show you the most popular board game in the Shanghai Ingress Resistance Team.
It all started several months ago. 
We found out the home address of the enlightened agent Icount2three and decided to draw him out. 
Millions of missiles were detonated, but some of them failed. 

After the event, we analysed the laws of failed attacks. 
It's interesting that the ii-th attacks failed if and only if ii can be rewritten as the form of 2a3b5c7d2a3b5c7d which a,b,c,da,b,c,d are non-negative integers. 

At recent dinner parties, we call the integers with the form 2a3b5c7d2a3b5c7d "I Count Two Three Numbers". 
A related board game with a given positive integer nn from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than nn.

Input

The first line of input contains an integer t (1≤t≤500000)t (1≤t≤500000), the number of test cases. tt test cases follow. Each test case provides one integer n (1≤n≤109)n (1≤n≤109).

Output

For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than nn.

Sample Input

10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789

Sample Output

1
12
14
125
1250
12348
123480
1234800
12348000
123480000

题目大意:

定义一组数,数是只含有2357四个因子。5e5次询问,每次询问一个x,让你输出这一组数中大于等于x的第一个数。

解题报告:

  对这组数打表,然后对于查询直接二分就行了。注意打表的时候可能爆longlong所以需要边打表边剪枝。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
ll a2[33],a3[33],a5[33],a7[33];
const ll INF = 1e9;
int tot;
ll db[MAX];
int main() 
{
	int t;
	ll a2=1,a3=1,a5=1,a7=1,n;
	for(ll i = 1; i<=33; i++,a2*=2) {
		ll tmp = a2;
		a3=1;
		for(ll j = 1; j<=33; j++,a3*=3) {
			tmp=a2*a3;
			if(tmp > INF) break;
			a5=1;
			for(int k = 1; k<=33; k++,a5*=5) {
				tmp=a2*a3*a5;
				if(tmp > INF) break;
				a7=1;
				for(int q = 1; q<=33; q++,a7*=7) {
					tmp=a2*a3*a5*a7;
					if(tmp > INF) break;
					db[++tot] = tmp;
				}
			}
		}
	}
	sort(db+1,db+tot+1);
	cin>>t;
	while(t--) {
		scanf("%lld",&n);
		int pos = lower_bound(db+1,db+tot+1,n) - db;
		printf("%lld\n",db[pos]);
	}
	return 0 ;
}