2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

I Count Two Three

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

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

Source

2016 ACM/ICPC Asia Regional Qingdao Online

题意: t组数据 给你一个n  输出不小于n的最短的数x

x=2^a*3^b*5^c*7^d

题解:因为最大为1e9  先打表找到所有的满足条件的数x 之后二分答案

 1 /******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<iostream>
 9 #include<cstring>
10 #include<cmath>
11 #include<cstdio>
12 #define ll long long
13 #define mod 1000000007
14 #define PI acos(-1.0)
15 #define N 1000000000
16 using namespace std;
17 int t;
18 ll a2[35]={1},a3[35]={1},a5[35]={1},a7[35]={1};
19 int jishu;
20 ll ans[50005];
21 void init()
22 {
23     jishu=0;
24     int er=0,san=0,wu=0,qi=0;
25     for(int i=1; a2[i-1]<=N;er++,i++)
26         a2[i]=a2[i-1]*2;
27     for(int i=1; a3[i-1]<=N;san++,i++)
28         a3[i]=a3[i-1]*3;
29     for(int i=1; a5[i-1]<=N;wu++,i++)
30         a5[i]=a5[i-1]*5;
31     for(int i=1; a7[i-1]<=N;qi++, i++)
32         a7[i]=a7[i-1]*7;
33     for(int i=0; i<er; i++)
34         for(int j=0; a2[i]*a3[j]<=N&&j<san; j++)
35             for(int k=0; a2[i]*a3[j]*a5[k]<=N&&k<wu; k++)
36                 for(int l=0; a2[i]*a3[j]*a5[k]*a7[l]<=N&&l<qi; l++)
37                     ans[jishu++]=a2[i]*a3[j]*a5[k]*a7[l];
38     sort(ans,ans+jishu);
39 }
40 int main()
41 {
42     int n;
43     while(scanf("%d",&t)!=EOF)
44     {
45         init();
46         for(int i=1; i<=t; i++)
47         {
48             scanf("%d",&n);
49             printf("%I64d\n",ans[lower_bound(ans,ans+jishu,n)-ans]);
50         }
51     }
52     return 0;
53 }
时间: 2024-10-18 07:32:38

2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分的相关文章

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题目大意: 给出一个数n ,求一个数X, X>=n. X 满足一个条件 X= 2^a*3^b*5^c*7^d 求靠近n的X值. 解题思路: 打表+二分查找 [切记用 cin cout,都是泪...] AC Code: 1 #include<bits/stdc++.h> 2 using namespace std; 3 long long na[100002]; 4 5 int main

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

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 star

HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 997    Accepted Submission(s): 306 Problem Description The empire is under attack again. The general of empire is planning to defend his

hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)

Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 208    Accepted Submission(s): 101 Problem Description You may not know this but it's a fact that Xinghai Square is

2016 ACM/ICPC Asia Regional Qingdao Online

吐槽: 群O的不是很舒服 不知道自己应该干嘛 怎样才能在团队中充分发挥自己价值 一点都不想写题 理想中的情况是想题丢给别人写 但明显滞后 一道题拖沓很久 中途出岔子又返回来搞 最放心的是微软微软妹可以随便丢 有几个小盆友也比较靠谱 还有几个小盆友一开始有点担心 后来都做的挺棒 写题的选择上很尴尬 会写的别人也会 要么队内都不会 结果大概是写了一些板子题 感觉到了比较艰难的阶段 有些题是要我学着去写的 不会写没有突破 1001 I Count Two Three AC by ctr 指数不会很大,

【2016 ACM/ICPC Asia Regional Qingdao Online】

[ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然后每次二分找就可以了. /* TASK:I Count Two Three 2^a*3^b*5^c*7^d的最小的大于等于n的数是多少 LANG:C++ URL:http://acm.hdu.edu.cn/showproblem.php?pid=5878 */ #include <iostream>

2016 ACM/ICPC Asia Regional Qingdao Online HDU5883

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883 解法:先判断是不是欧拉路,然后枚举 #pragma comment(linker, "/STACK:102400000,102400000") #include <math.h> #include <time.h> #include <stdio.h> #include <string.h> #include <stdlib.h>

2016 ACM/ICPC Asia Regional Qingdao Online HDU5889

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5889 解法:http://blog.csdn.net/u013532224/article/details/46992973 然后改改模版 #include <iostream> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <str

2016 ACM/ICPC Asia Regional Qingdao Online HDU5882

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5882 解法:一个点必须出度和入度相同就满足题意,所以加上本身就是判断奇偶性 #include<stdio.h> #include<math.h> #include<string.h> #include<stack> #include<set> #include<queue> #include<vector> #include<