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 ...
随机推荐
- android菜鸟学习笔记11----Intent的两点补充
关于Intent的两点补充: 1.隐式Intent启动组件,会有一个Intent解析的过程,若找不到能够处理该Intent的组件,程序就会异常终止.一个合理的做法是,在使用Intent实例启动组件如: ...
- Flask:基本结构
python有两个比较出名的网络框架,一个是django,一个是flask. 之前的django文章里面介绍了django的各种用法,这个系列开始介绍flask的用法.相比与django,flask更 ...
- python splinter chromedriver下载地址(国内可用)
http://chromedriver.storage.googleapis.com/index.html
- python——进程池
from concurrent.futures import ProcessPoolExecutor import os,random def func(name): print("%s吃了 ...
- python3用pdfminer3k在线读取pdf文件
import importlib import sys import random from urllib.request import urlopen from urllib.request imp ...
- [2018-12-18]ABP中的AsyncCrudAppService介绍
前言 自从写完上次略长的<用ABP入门DDD>后,针对ABP框架的项目模板初始化,我写了个命令行工具Abp-CLI,其中子命令abplus init可以从github拉取项目模板以初始化项 ...
- 关于android R.java文件无法创建的问题
R.java文件无法创建的原因网上有很多说法普遍是以下两种: 1. xml文件有错误: 解决方法就是找到哪个xml有错然后把错误修复就OK了. 2.编码问题 这时候只要把xml文件的编码改成utf8就 ...
- 基于springboot的RestTemplate、okhttp和HttpClient对比
1.HttpClient:代码复杂,还得操心资源回收等.代码很复杂,冗余代码多,不建议直接使用. 2.RestTemplate: 是 Spring 提供的用于访问Rest服务的客户端, RestTem ...
- VC++共享文件夹
BOOL NetShare(char * pShareName,char * pSharePath) { USES_CONVERSION; SHARE_INFO_502 si502; NET_API_ ...
- SGU 495 Kids and Prizes:期望dp / 概率dp / 推公式
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意: 有n个礼物盒,m个人. 最开始每个礼物盒中都有一个礼物. m个人依次随 ...