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 .
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
暴力预处理出所有的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;
else
r=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;
}