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 ii-th attacks failed if and only if ii can be rewritten as the form of 2a3b5c7d2a3b5c7d which a,b,c,da,b,c,d are non-negative integers.
At recent dinner parties, we call the integers with the form 2a3b5c7d2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integer nn from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than nn.
Input
The first line of input contains an integer t (1≤t≤500000)t (1≤t≤500000), the number of test cases. tt test cases follow. Each test case provides one integer n (1≤n≤109)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 nn.
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<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
#include<bitset>
using namespace std;
#define ll long long
const int mod=258280327;
const int maxn=1e6+10;
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
ll u[maxn];
ll mined(ll a,ll b,ll c,ll d)
{
b=min(a,b);
c=min(b,c);
d=min(c,d);
return d;
}
ll solve()
{
u[0]=1;
ll t2=0,t3=0,t5=0,t7=0;
for(ll i=1;; i++)
{
while(u[t2]*2<=u[i-1])
t2++;
while(u[t3]*3<=u[i-1])
t3++;
while(u[t5]*5<=u[i-1])
t5++;
while(u[t7]*7<=u[i-1])
t7++;
u[i]=mined(u[t2]*2,u[t3]*3,u[t5]*5,u[t7]*7);
if(u[i]>1000000000)
return i;
}
}
int main()
{
ll t,n;
ll k=solve();
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
ll l=lower_bound(u,u+k+1,n)-u;
printf("%lld\n",u[l]);
}
return 0;
}