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.

样例输入

  1. 10
  2. 1
  3. 11
  4. 13
  5. 123
  6. 1234
  7. 12345
  8. 123456
  9. 1234567
  10. 12345678
  11. 123456789

样例输出

  1. 1
  2. 12
  3. 14
  4. 125
  5. 1250
  6. 12348
  7. 123480
  8. 1234800
  9. 12348000
  10. 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很大,将表排个序,二分查找即可。

  1. #include<stdio.h>
  2. #include<algorithm>
  3. #define MAX 5200
  4. #define INF 0x3f3f3f3f
  5. using namespace std;
  6. typedef long long ll;
  7. ll a[MAX];
  8. ll mul(ll init,int x,int c)
  9. {
  10. ll ans=init;
  11. for(int i=;i<=c;i++){
  12. ans*=x;
  13. if(ans>) return ;
  14. }
  15. return ans;
  16. }
  17. int main()
  18. {
  19. int t,i,j,k,l;
  20. int tt=;
  21. for(i=;i<=;i++){
  22. ll ii=mul(,,i);
  23. if(ii==) continue;
  24. for(j=;j<=;j++){
  25. ll jj=mul(ii,,j);
  26. if(jj==) continue;
  27. for(k=;k<=;k++){
  28. ll kk=mul(jj,,k);
  29. if(kk==) continue;
  30. for(l=;l<=;l++){
  31. ll lll=mul(kk,,l);
  32. if(lll==) continue;
  33. a[++tt]=lll;
  34. }
  35. }
  36. }
  37. }
  38. sort(a+,a+tt+);
  39. ll n;
  40. scanf("%d",&t);
  41. while(t--){
  42. scanf("%lld",&n);
  43. ll ans=INF;
  44. int l=,r=tt,m;
  45. while(l<=r){
  46. m=(l+r)/;
  47. if(a[m]==n){
  48. ans=n;
  49. break;
  50. }
  51. if(a[m]<n){
  52. l=m+;
  53. }
  54. else{
  55. if(a[m]<ans) ans=a[m];
  56. r=m-;
  57. }
  58. }
  59. printf("%lld\n",ans);
  60. }
  61. return ;
  62. }

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. c++编码习惯

    1 大驼峰命名法 类名和函数名由单词构成,每个单词的首字母大写. 2 函数命名 大驼峰命名法. 3 类命名 大驼峰命名,但是为了和函数名区分开,在前面加上一个大写的C.

  2. 【docker】开启remote api访问,并使用TLS加密

    背景: docker默认是能使用本地的socket进行管理,这个在集群中使用的时候很不方便,因为很多功能还是需要链接docker服务进行操作,docker默认也可以开启tcp访问,但是这就相当于把整个 ...

  3. EASYARM-IMX283 制作ubifs文件系统

    ubifs主页:http://www.linux-mtd.infradead.org/doc/ubifs.html nandflash上常用的文件系统有jffs2.yaffs和ubifs,其中ubif ...

  4. 2048plus,可以直接分享到微信的2048

    点击图片下载apk包!!

  5. C++ 结构体多元素sort排序调用时的写法

    //总结一下,结构体数据排序的快速写法 //以后在遇到需要写的时候,不要迟疑快速写完 struct node { int u, v, w; }a[10000]; //假设该结构体有3个元素 //现在仅 ...

  6. UVA10294 Arif in Dhaka (First Love Part 2) —— 置换、poyla定理

    题目链接:https://vjudge.net/problem/UVA-10294 题解: 白书P146~147. 为什么旋转i个间距,就有gcd(i,n)个循环,且每个循环有n/gcd(i,n)个元 ...

  7. LVS与Keepalived

    lvs与Nginx区别 LVS的负载能力强,因为其工作方式逻辑非常简单,仅进行请求分发,而且工作在网络的第4层,没有流量,所以其效率不需要有过多的忧虑. LVS基本能支持所有应用,因为工作在第4层,所 ...

  8. vue 升降排序

    本实例是根据工作进度的百分比来进行排序. html <div class="ibox-content"> <li v-for="(rangeItem,i ...

  9. Win7 下安装MongoDB

    1).下载MongoDBhttp://downloads.mongodb.org/win32/mongodb-win32-i386-2.4.5.zip 下载Windows 32-bit版本并解压缩,程 ...

  10. DropDownList(For)

    1.绑定数据源 方法一 Controllers:var users = GetUsers(); var selectList = new SelectList(users, "Value&q ...