题目分析
枚举所有可能的结果,然后二分即可。
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 1e7+5;
LL arr[maxn];
int init(){
arr[0] = 1LL;
LL cur = 0;
for(int a = 0; a <= 32; a++)
for(int b = 0; b <= 21; b++)
for(int c = 0; c <= 20; c++)
for(int d = 0; d <= 19; d++){
LL x = (LL)pow(2.0,a)*pow(3.0,b)*pow(5.0,c)*pow(7.0,d);
if(x > 1e9) continue;
else arr[cur++] = x;
}
sort(arr, arr+cur);
return cur;
}
int main(){
int T, n, right;
right = init();
scanf("%d", &T);
while(T--){
scanf("%d", &n);
int l = 0, r = right-1;
while(l < r){
int mid = (l+r)/2;
if(arr[mid] < n) l = mid+1;
else r = mid;
}
printf("%I64d\n", arr[r]);
}
return 0;
}