您的位置:首页 > 理论基础 > 计算机网络

hdu5878 2016青岛网络赛-打表+二分

2016-09-17 20:10 411 查看


I Count Two Three

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 167    Accepted Submission(s): 96


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

 

Recommend

青岛网络赛

题意:给一个数x,求数y使得y的因子只有2 3 5 7 ,并且y要大于x,求最小的满足题意的y;

这个题打表,把以 2 3 5 7 为因子的数打出来然后排序,每次二分查找大于x 的数即可

AC代码:

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <set>
#include <math.h>
using namespace std;
const int maxn=1e6+100,up=1e9+1;
typedef long long LL;
LL a[maxn];
int main()
{
int m=32;
int tot=0;
for(int i=0;i<=m;i++)
{
if(pow(2,i)>=up)
break;
for(int j=0;j<=m;j++)
{
if(pow(2,i)*pow(3,j)>=up)
break;
for(int k=0;k<=m;k++)
{
if(pow(2,i)*pow(3,j)*pow(5,k)>=up)
break;
for(int l=0;l<=m;l++)
{
if(pow(2,i)*pow(3,j)*pow(5,k)*pow(7,l)>=up)
break;
a[tot++]=pow(2,i)*pow(3,j)*pow(5,k)*pow(7,l);
}
}
}
}
sort(a,a+tot);
LL n,x;
while(scanf("%lld",&n)!=-1)
{
while(n--)
{
scanf("%lld",&x);
printf("%lld\n",a[lower_bound(a,a+tot,x)-a]);
}
}

return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: