题干:

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 2a3b5c7d2a3b5c7d which a,b,c,da,b,c,d are non-negative integers.

At recent dinner parties, we call the integers with the form 2a3b5c7d2a3b5c7d "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

The first line of input contains an integer t (1≤t≤500000)t (1≤t≤500000), the number of test cases. tt test cases follow. Each test case provides one integer n (1≤n≤109)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 nn.

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

题目大意:

定义一组数,数是只含有2357四个因子。5e5次询问,每次询问一个x,让你输出这一组数中大于等于x的第一个数。

解题报告:

对这组数打表,然后对于查询直接二分就行了。注意打表的时候可能爆longlong所以需要边打表边剪枝。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
ll a2[33],a3[33],a5[33],a7[33];
const ll INF = 1e9;
int tot;
ll db[MAX];
int main()
{int t;ll a2=1,a3=1,a5=1,a7=1,n;for(ll i = 1; i<=33; i++,a2*=2) {ll tmp = a2;a3=1;for(ll j = 1; j<=33; j++,a3*=3) {tmp=a2*a3;if(tmp > INF) break;a5=1;for(int k = 1; k<=33; k++,a5*=5) {tmp=a2*a3*a5;if(tmp > INF) break;a7=1;for(int q = 1; q<=33; q++,a7*=7) {tmp=a2*a3*a5*a7;if(tmp > INF) break;db[++tot] = tmp;}}}}sort(db+1,db+tot+1);cin>>t;while(t--) {scanf("%lld",&n);int pos = lower_bound(db+1,db+tot+1,n) - db;printf("%lld\n",db[pos]);}return 0 ;
}

【HDU - 5878】I Count Two Three(打表)相关推荐

  1. HDU 5878 I Count Two Three

    打表,二分. 满足条件的数字个数不多,可以全部找出来,排个序,每次询问的时候二分一下. #pragma comment(linker, "/STACK:1024000000,10240000 ...

  2. mysql 左表为null_sql left join count 左表为空表的时候出现空行

    sql left join count 左表为空表的时候出现空行 mysql> CREATE TABLE `test`.`tab1` ( `id` INT NOT NULL AUTO_INCRE ...

  3. [codeforces 1327E] Count The Blocks 打表找规律+根据规律找公式+优化公式

    Educational Codeforces Round 84 (Rated for Div. 2)   比赛人数13522 [codeforces 1327E]  Count The Blocks  ...

  4. HDU - 5878 A - I Count Two Three H 技巧枚举

    题意 输入 t (1≤t≤500000), the number of test cases. t test cases follow. Each test case provides one int ...

  5. 我说 SELECT COUNT(*) 会造成全表扫描,面试官让我回去等通知

    来自:码海 前言 上篇 SQL 进阶技巧(下) 中提到使用以下 sql 会导致慢查询 SELECT COUNT(*) FROM SomeTable SELECT COUNT(1) FROM SomeT ...

  6. html统计筛选表格count,Excel中工作表数据进行计数和筛选的操作方法

    execl2007作为办公软件,统计数据的功能十分强大,如何对一个工作表的数据进行计数和筛选,今天,学习啦小编就教大家在Excel中工作表数据进行计数和筛选的操作方法. Excel中工作表数据进行计数 ...

  7. HDU 6155 Subsequence Count (DP、线性代数、线段树)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6155 题解 DP+线代好题.(考场上过多时间刚前两题,没怎么想这题--) 首先列出一个DP式: 设\( ...

  8. HDU - 2089 不要62 【暴力打表】【数位DP】

    不要62 HDU - 2089 题意 求区间[n,m]之间有多少个数字不含4或者连续的62 解法1 由于数据范围是0~1e6,所以直接暴力判断每一位数字是否含有4或者62,然后求前缀和即可 #incl ...

  9. 数学--数论--Hdu 5793 A Boring Question (打表+逆元)

    There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=? We define that (kj+1kj)=kj+1!kj! ...

最新文章

  1. gradle平级项目引用
  2. 排列与组合的一些定理(二)
  3. 连连看+php,java基于swing实现的连连看代码
  4. 【STM32】端口复用和重映射,完全重映射,部分重映射
  5. C/C++中涉及存储方式的关键字:auto,static,register,extern2009-01-22 11:23auto关键字:
  6. 为10号部门的员工涨工资
  7. QT线程使用收集示例
  8. 我的世界中国版服务器没有mods文件夹,我的世界中国版如何安装mod 国服安装mod的详细教程...
  9. concurrenthashmap_ConcurrentHashMap核心原理,这次彻底给整明白了
  10. 终于,我们的新产品Fotor Slideshow Maker上线了!!
  11. MKAnnotationView,MKAnnotation与MKMapView结合使用显示坐标点
  12. 第一节 ISM Web工业可视化组态软件简介
  13. 像素图片转矢量图片——从图像中提取曲线信息
  14. 深入PCI与PCIe之一:硬件篇
  15. C/C++基础题035.一元二次方程公式
  16. 【笔记总结】高中生物——【选一 Ⅰ】传统发酵技术的应用
  17. 西电计算机学院通知,西安电子科技大学计算机科学与技术学院关于发放2020级硕士研究生正式录取通知书的通知...
  18. Android 点九图机制讲解及在聊天气泡中的应用
  19. c语言 dct变换,DCT, IDCT变换--C语言实现
  20. 数学知识复习:三重积分

热门文章

  1. 数据结构四——散列表(下)
  2. 解释为脑瘫的那张图_Python GIL全局解释器锁详解(深度剖析)
  3. python创建虚拟环境失败_?conda创建虚拟环境失败,如何解决?
  4. 爬楼梯(递归——奇数步,偶数步扩展)
  5. hbase filter原理_HBase应用|HBase在移动广告监测产品中的应用
  6. idea 下划线字段转驼峰_Java如何实现数据库中表字段的下划线和驼峰式命名的Model相互转换,很方便的...-Go语言中文社区...
  7. android 对话框 图片,android – AlertDialog按钮的图像
  8. php编译称opcode文件,PHP源码保护和性能加速
  9. mongodb 库数量限制_MongoDB in 数量限制
  10. asterisk使用MYSQL认证的配置方法