I Count Two Three

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 767    Accepted Submission(s): 403

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
 
 
 
解析:预处理得到满足条件的数,再二分查询。预处理可参考http://blog.csdn.net/coder_xia/article/details/6707600
 
 
 
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std; ll a[10000]; void get(int n)
{
a[0] = 1;
int n2 = 0;
int n3 = 0;
int n5 = 0;
int n7 = 0;
int cnt = 1;
while(cnt < n){
ll t1 = min(a[n2]*2, a[n3]*3);
ll t2 = min(a[n5]*5, a[n7]*7);
ll t = min(t1, t2);
if(t == a[n2]*2)
++n2;
if(t == a[n3]*3)
++n3;
if(t == a[n5]*5)
++n5;
if(t == a[n7]*7)
++n7;
a[cnt++] = t;
}
} int main()
{
get(5200);
int t, n;
scanf("%d", &t);
while(t--){
scanf("%d", &n);
printf("%I64d\n", *lower_bound(a, a+5219, n));
}
return 0;
}

  

HDU 5878 I Count Two Three的更多相关文章

  1. hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题目大意: 给出一个数n ,求一个数X, X>=n. X 满足一个条件 X= 2^a*3^ ...

  2. 数学--数论--hdu 5878 I Count Two Three(二分)

    I will show you the most popular board game in the Shanghai Ingress Resistance Team. It all started ...

  3. HDU 5878 I Count Two Three (打表+二分查找) -2016 ICPC 青岛赛区网络赛

    题目链接 题意:给定一个数n,求大于n的第一个只包含2357四个因子的数(但是不能不包含其中任意一种),求这个数. 题解:打表+二分即可. #include <iostream> #inc ...

  4. HDU 5878 I Count Two Three (预处理+二分查找)

    题意:给出一个整数nnn, 找出一个大于等于nnn的最小整数mmm, 使得mmm可以表示为2a3b5c7d2^a3^b5^c7^d2​a​​3​b​​5​c​​7​d​​. 析:预处理出所有形为2a3 ...

  5. 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 ...

  6. I Count Two Three HDU - 5878(暴力二分)

    为甚么16年Qingdao Online 都是暴力题emm///... 先暴力预处理 然后lower _bound二分 #include <iostream> #include <c ...

  7. 【HDU 4372】 Count the Buildings (第一类斯特林数)

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  8. HDU——T 3336 Count the string

    http://acm.hdu.edu.cn/showproblem.php?pid=3336 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  9. hdu 5056 Boring count

    贪心算法.需要计算分别以每个字母结尾的且每个字母出现的次数不超过k的字符串,我们设定一个初始位置s,然后用游标i从头到尾遍历字符串,使用map记录期间各个字母出现的次数,如果以s开头i结尾的字符串满足 ...

随机推荐

  1. mySql 自动备份数据库

    mysqldump -u root -proot -h 192.168.1.100 xqpd > 1.sqlcopy 1.sql D:\项目备份\工程_数据库-%date:~0,4%%date: ...

  2. zju 1037 Gridland(找规律,水题)

    题目链接 多写几个案例,根据数据的奇偶性,就能找到规律了 #include<stdio.h> int main() { int t,n,m; double ans; scanf(" ...

  3. ****Git 常用命令和使用思维导图

    Git 是一个很强大的分布式版本控制系统.它不但适用于管理大型开源软件的源代码,管理私人的文档和源代码也有很多优势. 本来想着只把最有用.最常用的 Git 命令记下来,但是总觉得这个也挺有用.那个也用 ...

  4. HDU 3507 Print Article(斜率优化DP)

    题目链接 题意 : 一篇文章有n个单词,如果每行打印k个单词,那这行的花费是,问你怎么安排能够得到最小花费,输出最小花费. 思路 : 一开始想的简单了以为是背包,后来才知道是斜率优化DP,然后看了网上 ...

  5. Sina App Engine(SAE)入门教程(3)-KVDB使用

    简介 因为传统关系型数据库在分布式环境下表现的扩展性不足等缺点,近年来NoSQL的概念渐渐成为业界关注的焦点,越来越多的技术人员也习惯于使用NoSQL数据库进行日常开发,SAE为了应对这种新需求,也进 ...

  6. [Unity菜鸟] 射线

    1. 射线用 Physics.Raycast 都可以判断,用 collider.Raycast 只在某些(不明)情况下可以 void Update() { Ray ray = Camera.main. ...

  7. C++:用成员初始化列表对数据成员初始化

    1.在声明类时,对数据成员的初始化工作一般在构造函数中用赋值语句进行. 例如: class Complex{ private: double real; double imag; public: Co ...

  8. 在C#中实现Python的分片技术

    在C#中实现Python的分片技术 前言 之前在学习Python的时候发现Python中的分片技术超好玩的,本人也是正则表达式热爱狂,平时用C#比较多,所以决定把Python中的分片技术在C#中实现, ...

  9. The type sun.management.ManagementFactory is not visible

    Eclipse默认将这些受访问限制的API设成了Error.解决方法:只要将Windows---Preferences---Java--Complicer---Errors/Warings里面的Dep ...

  10. 一行很好的JS代码

    [].forEach.call($$("*"),function(a){ a.style.outline="1px solid #"+(~~(Math.rand ...