A - I Count Two Three ( 打表+二分 )
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
题意:找到一个大于等于输入x的数,满足。
思路:打表找到所有满足的数,二分查找大于等于x的数。 输入输出用scanf,printf
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
ll a[maxn],cnt;
ll qpow( ll a, ll n )
{
ll re = 1;
while ( n ) {
if ( n&1 ) {
re *= a;
}
n >>= 1;
a *= a;
}
return re;
}
void init()
{
int i,j,k,l;
for ( i=0; i<=30; i++ ) {
for ( j=0; j<=20; j++ ) {
for ( k=0; k<=14; k++ ) {
for ( l=0; l<=12; l++ ) {
ll ans = qpow(2,i)*qpow(3,j)*qpow(5,k)*qpow(7,l);
if ( ans<=1000000000 ) {
a[cnt++] = ans;
}
}
}
}
}
}
int main()
{
cnt = 0;
init();
ll listt,x;
cin >> listt;
sort(a,a+cnt);
while ( listt-- ) {
scanf("%lld",&x);
printf("%lld\n",a[lower_bound(a,a+cnt,x)-a] );
}
return 0;
}