题意找出大于等于 n 的最小的 能表示为 2的a次 乘以 3的b次 乘以 5的c次 乘以 7的d次 的数。
n最大为1e9,符合条件的数也没几个,预处理出来,排个序,二分一下就好了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
using namespace std;
typedef long long LL;
const LL MAX = 1000000000;
LL ans[20000];
int cnt = 0;
LL Power(LL a, LL b)
{
LL ans = 1;
while (b > 0)
{
if (b&1)
ans *= a;
b >>= 1;
a *= a;
}
return ans;
}
void init()
{
LL tmp;
for(int a = 0; a <= 31; a++)
{
for(int b = 0; b <= 19; b++)
{
for(int c = 0; c <= 12; c++)
{
for(int d = 0; d <= 11; d ++)
{
tmp = Power(2, a)*Power(3, b);
if(tmp > MAX) break;
tmp *= Power(5, c);
if(tmp > MAX) break;
tmp *= Power(7, d);
if(tmp > MAX) break;
ans[++cnt] = tmp;
}
}
}
}
}
int bisearch(int x)
{
if(x == 1) return 1;
int l = 1, r = cnt + 1, m;
while(l < r)
{
m = (l + r) >> 1;
if(ans[m] > x) r = m;
else if(ans[m] == x) return ans[m];
else l = m + 1;
}
return ans[l];
}
int main()
{
init();
sort(ans + 1, ans + 1 + cnt);
int T;
scanf("%d", &T);
while(T--)
{
int tmp;
scanf("%d", &tmp);
printf("%d\n", bisearch(tmp));
}
return 0;
}