時空門
預處理 + 二分
預處理:先用三層for找到所有的隻含有2,3,5因子的數,然後排序。
二分:lower_bound 傳回一個指針,即>= value的最小數的位置。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <bitset>
using namespace std;
#define eps (1e-6)
#define LL long long
#define pi acos(-1.0)
#define rd(a) (a = read())
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(x,to) for(int x=0;x<(to);++x)
#define FORR(x,arr) for(auto& x:arr)
#define LOOP(x,k,to) for(int x=k;x<(to);++x)
#define ITR(x,c) for(auto x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin(),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define PRINT(a,b) cout << "#" << (a) << " " << (b) << endl
#define DEBUG(a,b) cout << "$" << (a) << " " << (b) << endl
#define line cout << "\n--------------------\n"
const LL INF = 1e18+100;
const int MAXN = 1e6+5;
int tot = 0;
LL t,n,pos;
LL ans[MAXN];
void CONFIRM()
{
for(LL i=0; i<100; ++i){
PRINT(i, ans[i]);
}
line;
}
void INIT()
{
for(LL i=1; i<INF; i*=2){
for(LL j=1; i*j<INF; j*=3){
for(LL k=1; i*j*k<INF; k*=5){
ans[tot++] = i*j*k;
}
}
}
sort(ans, ans+tot);
//CONFIRM();
return;
}
int main()
{
IOS;
INIT();
cin >> t;
while(t--){
cin >> n;
cout << *lower_bound(ans+1, ans+tot+1, n) << endl;
}
return 0;
}