HDU 5878 I Count Two Three
生活随笔
收集整理的這篇文章主要介紹了
HDU 5878 I Count Two Three
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
打表,二分。
滿足條件的數(shù)字個(gè)數(shù)不多,可以全部找出來(lái),排個(gè)序,每次詢問(wèn)的時(shí)候二分一下。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0),eps=1e-6; void File() {freopen("D:\\in.txt","r",stdin);freopen("D:\\out.txt","w",stdout); } template <class T> inline void read(T &x) {char c=getchar(); x=0;while(!isdigit(c)) c=getchar();while(isdigit(c)) {x=x*10+c-'0'; c=getchar();} }const int maxn=100010; LL M=2e9; LL p[maxn]; int sz=0;int main() {LL a=1;for(int i=0;;i++){if(i!=0) a=a*2; if(a>M) break;LL b=1;for(int j=0;;j++){if(j!=0) b=b*3; if(b>M||a*b>M) break;LL c=1;for(int s=0;;s++){if(s!=0) c=c*5; if(c>M||a*b*c>M) break;LL d=1;for(int k=0;;k++){if(k!=0) d=d*7; if(d>M||a*b*c*d>M) break;p[sz++]=a*b*c*d;}}}}sort(p,p+sz);int T; scanf("%d",&T);while(T--){LL n; scanf("%lld",&n);int L=0,R=sz-1,pos;while(L<=R){int m=(L+R)/2;if(p[m]<n) L=m+1;else if(p[m]==n) { pos=m; break; }else pos=m,R=m-1;}printf("%lld\n",p[pos]);}return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/zufezzt/p/5887011.html
超強(qiáng)干貨來(lái)襲 云風(fēng)專(zhuān)訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
以上是生活随笔為你收集整理的HDU 5878 I Count Two Three的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: bzoj1230[Usaco2008 N
- 下一篇: MySQL的insert ignore与