hdu 5878 I Count Two Three 2016ACM/ICPC青岛赛区网络赛1001

来源:互联网 发布:安装ubuntu分区顺序 编辑:程序博客网 时间:2024/05/16 05:45

Problem Description
I will show you the most popular board game in the Shanghai Ingress Resistance Team.
It all started several months ago.
We found out the home address of the enlightened agent Icount2three and decided to draw him out.
Millions of missiles were detonated, but some of them failed.

After the event, we analysed the laws of failed attacks.
It's interesting that the i-th attacks failed if and only if i can be rewritten as the form of 2a3b5c7d which a,b,c,d are non-negative integers.

At recent dinner parties, we call the integers with the form 2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n.
 

Input
The first line of input contains an integer t (1t500000), the number of test cases. t test cases follow. Each test case provides one integer n (1n109).
 

Output
For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than n.
 

Sample Input
1011113123123412345123456123456712345678123456789
 

Sample Output
11214125125012348123480123480012348000123480000

暴力预处理出所有的10^9以内只有2,3,5,7因子的数

然后直接二分查找即可

#include<map>#include<cmath>#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespace std;long long a[10000001];inline long long findx(int l,int r,long long x){while(l<=r){int mid=(l+r)/2;if(a[mid]<x)l=mid+1;elser=mid-1;}return a[l];}int main(){int i,j,k,l;long long ii=1,jj,kk,ll; int tot=0;for(i=0;i<=32;i++){long long ans=ii;jj=1;for(j=0;j<=19;j++){ans*=jj;if(ans>1000000000){ans/=jj;break;}kk=1;for(k=0;k<=13;k++){ans*=kk;if(ans>1000000000){ans/=kk;break;}ll=1;for(l=0;l<=11;l++){ans*=ll;if(ans>1000000000){ans/=ll;break;}tot++;a[tot]=ans;ans/=ll;ll*=7LL;}ans/=kk;kk*=5LL;}ans/=jj;jj*=3LL;}ans/=ii;ii*=2LL;}sort(a+1,a+1+tot);int T;scanf("%d",&T);while(T>0){T--;int n;scanf("%d",&n);printf("%I64d\n",findx(1,tot,n));}return 0;}


0 0
原创粉丝点击