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. android菜鸟学习笔记11----Intent的两点补充

    关于Intent的两点补充: 1.隐式Intent启动组件,会有一个Intent解析的过程,若找不到能够处理该Intent的组件,程序就会异常终止.一个合理的做法是,在使用Intent实例启动组件如: ...

  2. 九度OJ 1009:二叉搜索树 (二叉树)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6321 解决:2767 题目描述: 判断两序列是否为同一二叉搜索树序列 输入: 开始一个数n,(1<=n<=20) 表示有n个需 ...

  3. mysql系列之8.mysql高可用 (mha4mysql)

    环境: 三台机器 主服务器: 192.168.1.130 主备机器: 192.168.1.131 监控机器: 192.168.1.132 130和131, 是mysql双主架构 1.在三台机器上安装m ...

  4. 一文快速搞懂MySQL InnoDB事务ACID实现原理(转)

    这一篇主要讲一下 InnoDB 中的事务到底是如何实现 ACID 的: 原子性(atomicity) 一致性(consistency) 隔离性(isolation) 持久性(durability) 隔 ...

  5. 我的Android进阶之旅------>报 error: Apostrophe not preceded by \ 的错误解决办法

    今天对项目进行国际化翻译的时候控制台出现了以下的错误: res/values/strings.xml:100: error: Apostrophe not preceded by \ (in Sorr ...

  6. jxl java工具类,导出excel,导入数据库

    1: 引入jxl jar 我使用的为maven管理, <!--Excel工具--> <dependency> <groupId>net.sourceforge.je ...

  7. sap 图标查看

    showicon这个程序很不错,可以显示SAP里所有的ICON(图标). 用事务码SE38直接运行程序:showicon 即可. 显示列表之后,双击任何一个图标可以显示出每一个图标的详细信息.

  8. CodeIgniter底层数据库类继承关系

    1.CI_DB_mysql_driver 继承 CI_DB,  CI_DB这个类是不存在的,每次调用文件中~/CodeIgniter_2.1.3/system/database/DB.php函数&am ...

  9. Machine Learning No.4: Regularization

    1. Underfit = High bias Overfit = High varience 2. Addressing overfitting: (1) reduce number of feat ...

  10. 【Leetcode-easy】Palindrome Number

    思路:除和求余 取得首位和末尾 比较是否相等. public boolean isPalindrome(int x){ if(x<0){ return false; } int div=1; w ...