2016 ACM/ICPC Asia Regional Qingdao Online 1001 I Count Two Three

时间:2022-03-18 01:04:52

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

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 (1≤t≤500000), the number of test cases. t test cases follow. Each test case provides one integer n (1≤n≤109).
 



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
10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789
 



Sample Output
1
12
14
125
1250
12348
123480
1234800
12348000
123480000
 
先打表,然后二分搜索做
 #include <iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<set>
using namespace std;
int t,x,len;
int arr[];
int main()
{
len=;
for(int a=;a<=;a++)
{
double aa=pow(2.0,a*1.0);
for(int b=;b<=;b++)
{
double bb=pow(3.0,b*1.0);
if (aa*bb>=1200000000.0) break;
for(int c=;c<=;c++)
{
double cc=pow(5.0,c*1.0);
if (aa*bb*cc>=1200000000.0) break;
for(int d=;d<=;d++)
{
double dd=pow(7.0,d*1.0);
if (aa*bb*cc*dd>=1200000000.0) break;
arr[++len]=(int)aa*bb*cc*dd;
}
}
}
}
sort(arr+,arr+len+);
//printf("%d\n",arr[len]);
//for(int i=1;i<=len;i++) printf("%d ",arr[i]);
// printf("%d\n",len);
while(scanf("%d",&t)!=EOF)
{
for(;t>;t--)
{
scanf("%d",&x); // set<int> s;
// s.insert(1);
// while(!s.empty())
// {
// set<int>::iterator ii;
// ii=s.begin();
// if (*ii>=x) {printf("%d\n",*ii); break;}
// s.erase(s.begin());
// int k=*ii;
// if(k*2<1200000000) s.insert(k*2);
// if(k*3<1200000000) s.insert(k*3);
// if(k*5<1200000000) s.insert(k*5);
// if(k*7<1200000000) s.insert(k*7);
// } int l=,r=len;
while(l<r)
{
int mid=(l+r)/;
if (arr[mid]<x) l=mid+;
else r=mid;
}
printf("%d\n",arr[l]); }
}
return ;
}