标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 782 Accepted Submission(s): 406
1 /****************************** 2 code by drizzle 3 blog: www.cnblogs.com/hsd-/ 4 ^ ^ ^ ^ 5 O O 6 ******************************/ 7 #include<bits/stdc++.h> 8 #include<iostream> 9 #include<cstring> 10 #include<cmath> 11 #include<cstdio> 12 #define ll long long 13 #define mod 1000000007 14 #define PI acos(-1.0) 15 #define N 1000000000 16 using namespace std; 17 int t; 18 ll a2[35]={1},a3[35]={1},a5[35]={1},a7[35]={1}; 19 int jishu; 20 ll ans[50005]; 21 void init() 22 { 23 jishu=0; 24 int er=0,san=0,wu=0,qi=0; 25 for(int i=1; a2[i-1]<=N;er++,i++) 26 a2[i]=a2[i-1]*2; 27 for(int i=1; a3[i-1]<=N;san++,i++) 28 a3[i]=a3[i-1]*3; 29 for(int i=1; a5[i-1]<=N;wu++,i++) 30 a5[i]=a5[i-1]*5; 31 for(int i=1; a7[i-1]<=N;qi++, i++) 32 a7[i]=a7[i-1]*7; 33 for(int i=0; i<er; i++) 34 for(int j=0; a2[i]*a3[j]<=N&&j<san; j++) 35 for(int k=0; a2[i]*a3[j]*a5[k]<=N&&k<wu; k++) 36 for(int l=0; a2[i]*a3[j]*a5[k]*a7[l]<=N&&l<qi; l++) 37 ans[jishu++]=a2[i]*a3[j]*a5[k]*a7[l]; 38 sort(ans,ans+jishu); 39 } 40 int main() 41 { 42 int n; 43 while(scanf("%d",&t)!=EOF) 44 { 45 init(); 46 for(int i=1; i<=t; i++) 47 { 48 scanf("%d",&n); 49 printf("%I64d\n",ans[lower_bound(ans,ans+jishu,n)-ans]); 50 } 51 } 52 return 0; 53 }
2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5894131.html