I Count Two Three

  • 31.1%
  • 1000ms
  • 32768K
 

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 2^a3^b5^c7^d2a3b5c7d which a,\ b,\ c,\ da, b, c, d are non-negative integers.

At recent dinner parties, we call the integers with the form 2^a3^b5^c7^d2a3b5c7d "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 Format

The first line of input contains an integer t (1\le t \le 500000)t(1≤t≤500000), the number of test cases. tt test cases follow. Each test case provides one integer n (1\le n\le 10^9)n(1≤n≤109).

Output Format

For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than nn.

样例输入

10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789

样例输出

1
12
14
125
1250
12348
123480
1234800
12348000
123480000

题目来源

ACM-ICPC 2016 Qingdao Preliminary Contest

这道题类似于之前的51Nod - 1284找2 3 5 7的倍数,求出2 3 5 7最小公倍数210找循环节。

本题是2^a*3^b*5^c*7^d,无法从gcd循环节入手,于是就把10^9之内满足条件的值打出表来,发现只有5194个。

由于t很大,将表排个序,二分查找即可。

#include<stdio.h>
#include<algorithm>
#define MAX 5200
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
ll a[MAX];
ll mul(ll init,int x,int c)
{
ll ans=init;
for(int i=;i<=c;i++){
ans*=x;
if(ans>) return ;
}
return ans;
}
int main()
{
int t,i,j,k,l;
int tt=;
for(i=;i<=;i++){
ll ii=mul(,,i);
if(ii==) continue;
for(j=;j<=;j++){
ll jj=mul(ii,,j);
if(jj==) continue;
for(k=;k<=;k++){
ll kk=mul(jj,,k);
if(kk==) continue;
for(l=;l<=;l++){
ll lll=mul(kk,,l);
if(lll==) continue;
a[++tt]=lll;
}
}
}
}
sort(a+,a+tt+);
ll n;
scanf("%d",&t);
while(t--){
scanf("%lld",&n);
ll ans=INF;
int l=,r=tt,m;
while(l<=r){
m=(l+r)/;
if(a[m]==n){
ans=n;
break;
}
if(a[m]<n){
l=m+;
}
else{
if(a[m]<ans) ans=a[m];
r=m-;
}
}
printf("%lld\n",ans);
}
return ;
}

HDU - 5878 2016青岛网络赛 I Count Two Three(打表+二分)的更多相关文章

  1. HDU - 5887 2016青岛网络赛 Herbs Gathering(形似01背包的搜索)

    Herbs Gathering 10.76% 1000ms 32768K   Collecting one's own plants for use as herbal medicines is pe ...

  2. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

  3. HDU 5886 Tower Defence(2016青岛网络赛 I题,树的直径 + DP)

    题目链接  2016 Qingdao Online Problem I 题意  在一棵给定的树上删掉一条边,求剩下两棵树的树的直径中较长那的那个长度的期望,答案乘上$n-1$后输出. 先把原来那棵树的 ...

  4. HDU 5877 2016大连网络赛 Weak Pair(树状数组,线段树,动态开点,启发式合并,可持久化线段树)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Tota ...

  5. HDU5887 Herbs Gathering(2016青岛网络赛 搜索 剪枝)

    背包问题,由于数据大不容易dp,改为剪枝,先按性价比排序,若剩下的背包空间都以最高性价比选时不会比已找到的最优解更好时则剪枝,即 if(val + (LD)pk[d].val / (LD)pk[d]. ...

  6. HDU5880 Family View(2016青岛网络赛 AC自动机)

    题意:将匹配的串用'*'代替 tips: 1 注意内存的使用,据说g++中指针占8字节,c++4字节,所以用g++交会MLE 2 注意这种例子, 12abcdbcabc 故失败指针要一直往下走,否则会 ...

  7. 2016青岛网络赛 Barricade

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Proble ...

  8. 2016青岛网络赛 Sort

    Sort Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Des ...

  9. 2016青岛网络赛 The Best Path

    The Best Path Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Pr ...

随机推荐

  1. java array

    1 array变量 Type[] array_virable_name; 2 array对象 2.1 new Type[] array_virable_name = new Type[NUM]; 2. ...

  2. sys添加路径

    暂时更改sys.path sys.path.append()

  3. 解决ubuntu12.04下安装gitlabError Compiling CSS asset的错误以及401资源错误

    安装过程 https://www.gitlab.com.cn/installation/#ubuntu 解决过程 12.04ubuntu坑太多 解决有用的链接如下 https://blog.csdn. ...

  4. vue 动态传值笔记

    :prop="'answers.a' + item.split('.')[1]+'.total'" {{scope.row.answers['a'+item.split('.')[ ...

  5. Eclipse的.properties文件输出中文成unicode编码

    今天添加log4j.properties时,无法输入中文,输入的中文直接变成了unicode的编码形式.原因是Eclipse的.properties文件的默认编码为iso-8859-1. 选择Wind ...

  6. Linux学习之路(一)命令基本格式

    据统计Linxu里面能够识别的命令超过3000个,而我们常用的Linux基本命令在60个左右.常用命令是我们必须掌握的命令,需要我们多练习才能记住,最起码要敲3遍以上. 简单的把常用命令分为以下几大类 ...

  7. PHP的深copy和浅copy

    1.对象复制的由来 为什么对象会有“复制”这个概念,这与PHP5中对象的传值方式是密切相关的,让我们看看下面这段简单的代码 /** * 电视机类 */ class Television { /** * ...

  8. 时间序列数据库——索引用ES、聚合分析时加载数据用什么?docvalues的列存储貌似更优优势一些

    加载 如何利用索引和主存储,是一种两难的选择. 选择不使用索引,只使用主存储:除非查询的字段就是主存储的排序字段,否则就需要顺序扫描整个主存储. 选择使用索引,然后用找到的row id去主存储加载数据 ...

  9. codeforces 660B B. Seating On Bus(模拟)

    题目链接: B. Seating On Bus time limit per test 1 second memory limit per test 256 megabytes input stand ...

  10. Qt属性系统(Qt Property System)

    Qt提供了巧妙的属性系统,它与某些编译器支持的属性系统相似.然而,作为平台和编译器无关的库,Qt不能够依赖于那些非标准的编译器特性,比如__property 或者 [property].Qt的解决方案 ...