I Count Two Three
二分查找用lower_bound
这道题用cin,cout会超时。。。
AC代码;
1 /* */ 2 # include <iostream> 3 # include <cstring> 4 # include <string> 5 # include <cstdio> 6 # include <cmath> 7 # include <algorithm> 8 using namespace std; 9 10 const int TWO = 2; 11 const int THREE = 3; 12 const int FIVE = 5; 13 const int SEVEN = 7; 14 15 const long long MAXN = 1e9+100; 16 const int N=1e6; 17 long long a[N]; 18 int m; 19 20 void maketable() 21 { 22 m=0; 23 for(long long i=1; i<MAXN; i*=TWO ) 24 { 25 for(long long j=1; j*i<MAXN; j*=THREE ) 26 { 27 for(long long k=1; i*j*k<MAXN; k*=FIVE ) 28 { 29 for(long long l=1; i*j*k*l<MAXN; l*=SEVEN ) 30 { 31 a[m++] = i*j*k*l; 32 } 33 } 34 } 35 } 36 } 37 38 int main() 39 { 40 ios::sync_with_stdio(false); 41 maketable(); 42 sort(a,a+m); 43 int t; 44 long long n; 45 scanf("%d", &t); 46 //cin>>t; 47 while( t-- ) 48 { 49 scanf("%lld",&n); 50 printf("%lld\n", *lower_bound(a, a+m, n)); 51 // cin>>n; 52 // cout<<*lower_bound(a,a+m,n)<<endl; 53 } 54 return 0; 55 }
原文地址:https://www.cnblogs.com/wsy107316/p/11462628.html
时间: 2024-10-10 20:25:30