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

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 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

AC代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

long long Ta[104200];
int tot=0;
void maketable(){
	tot=0;
	for(int i=0;i<=30;++i){
		for(int j=0;j<=19;j++){
			for(int n=0;n<=13;n++){
				for(int k=0;k<=11;++k){
					Ta[tot++]=pow(2,i)*pow(3,j)*pow(5,n)*pow(7,k);
				} 
			}  
		}
	}
} 

long long T,n;
int main(){
	cin>>T;
	maketable();
	sort(Ta,Ta+tot);
	while(T--){

		int ans=0;
		scanf("%lld",&n);
		printf("%lld\n", *lower_bound(Ta, Ta + tot, n));
		
	}
} 

第一次做这个题的时候暴力到崩了。总是T,第一次遇到打表这个名词,不过一听这个名词就明白了,pow(2,a)*pow(3,b)*pow(5,c)*pow(7,d) 总共不过1e6数。所有结果列出来就二分了查找了。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值