HDU - 5878 2016青岛网络赛 I Count Two Three(打表+二分)
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(打表+二分)的更多相关文章
- HDU - 5887 2016青岛网络赛 Herbs Gathering(形似01背包的搜索)
Herbs Gathering 10.76% 1000ms 32768K Collecting one's own plants for use as herbal medicines is pe ...
- HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)
题目链接 2016 青岛网络赛 Problem C 题意 给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...
- HDU 5886 Tower Defence(2016青岛网络赛 I题,树的直径 + DP)
题目链接 2016 Qingdao Online Problem I 题意 在一棵给定的树上删掉一条边,求剩下两棵树的树的直径中较长那的那个长度的期望,答案乘上$n-1$后输出. 先把原来那棵树的 ...
- HDU 5877 2016大连网络赛 Weak Pair(树状数组,线段树,动态开点,启发式合并,可持久化线段树)
Weak Pair Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Tota ...
- HDU5887 Herbs Gathering(2016青岛网络赛 搜索 剪枝)
背包问题,由于数据大不容易dp,改为剪枝,先按性价比排序,若剩下的背包空间都以最高性价比选时不会比已找到的最优解更好时则剪枝,即 if(val + (LD)pk[d].val / (LD)pk[d]. ...
- HDU5880 Family View(2016青岛网络赛 AC自动机)
题意:将匹配的串用'*'代替 tips: 1 注意内存的使用,据说g++中指针占8字节,c++4字节,所以用g++交会MLE 2 注意这种例子, 12abcdbcabc 故失败指针要一直往下走,否则会 ...
- 2016青岛网络赛 Barricade
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Proble ...
- 2016青岛网络赛 Sort
Sort Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Des ...
- 2016青岛网络赛 The Best Path
The Best Path Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Pr ...
随机推荐
- redis自启动
$ vi /etc/init.d/redis # chkconfig: 2345 90 10 # description: Redis is a persistent key-value databa ...
- freetype下载和配置
一 下载编译freetype库 1 下载 地址:http://www.freetype.org/ 得到压缩文件:freetype-2.5.3.tar.gz 2 解压: 直接解压,得到文件夹freety ...
- Java基础教程:多线程基础(3)——阻塞队列
Java基础教程:多线程基础(3)——阻塞队列 快速开始 引入问题 生产者消费者问题是线程模型中的经典问题:生产者和消费者在同一时间段内共用同一存储空间,生产者向空间里生产数据,而消费者取走数据. 模 ...
- IOS AFNetWorking 设置超时时间
(原创经验总结) 1.关于AF 超时的说法 系统默认的timeInterval 是60s ASI默认是10s 但是有一个说法是 AF “AFN在GET条件下设置的NSURLRequest能起作用, ...
- centos下安装wordpress
https://www.jianshu.com/p/2439dc2187b2 https://blog.csdn.net/liuhelong/article/details/79924014
- js中得~~是什么意思/JS按位非(~)运算符与~~运算符的理解分析
其实是一种利用符号进行的类型转换,转换成数字类型 ~~true == 1 ~~false == 0 ~~"" == 0 ~~[] == 0 ~~undefined ==0 ~~!u ...
- 初入 CLR - 阅读《CLR via C#》笔记
最近买了一本书<CLR via C#>阅读了第一章 - CLR 的执行模型,对 .NET 一直提到的 CLR 和 .NET Framework 有了一个大致的了解.我理解主要体现在: ■ ...
- hdu-5818 Joint Stacks(模拟)
题目链接: Joint Stacks Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu-5804 Price List(水题)
题目链接: Price List Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Othe ...
- arm-linux-gcc4.4.3编译busybox-1.25.0
系统环境: 1.操作系统:Ubuntu16.04 2.交叉编译工具链:arm-linux-gcc4.4.3 3.busybox源码包:busybox-1.25.0 一.修改Makefile配置 首先解 ...