打表二分。。后来发现这是51nod中的一个原题
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 typedef long long int ll; 6 const ll INF = 1e9 + 100000; 7 ll a[100005]; 8 int cnt = 0; 9 int x[] = {2,3,5, 7}; 10 void dfs(int pos, ll num){ 11 if(pos == 4) { 12 a[cnt++] = num; 13 return; 14 } 15 dfs(pos+1, num); 16 for(int i = 1; i <= 32; i++){ 17 if(num*x[pos]> INF) break; 18 dfs(pos+1, num *= x[pos]); 19 } 20 } 21 int main() 22 { 23 dfs(0,1); 24 sort(a, a+cnt); 25 int t; 26 scanf("%d", &t); 27 while(t--){ 28 ll y; 29 scanf("%I64d", &y); 30 int ans = lower_bound(a, a+cnt, y) - a; 31 printf("%I64d\n", a[ans]); 32 } 33 34 return 0; 35 }
时间: 2024-10-13 22:27:58