hdu 5878
I Count Two Three
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2719 Accepted Submission(s): 1177
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.
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
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstdlib> 5 #include <cstring> 6 #include <string> 7 #include <deque> 8 #include <vector> 9 #include <set> 10 using namespace std; 11 #define ll long long 12 #define P pair<int,int> 13 const int N= 5e3+1000; 14 const ll M = 1000000000; 15 ll n,a[N]; 16 int cnt =0; 17 int t; 18 ll pow(ll a,ll b){ 19 ll ans=1; 20 while(b){ 21 if(b&1) ans=ans*a; 22 b>>=1; 23 a*=a; 24 } 25 return ans; 26 } 27 void init() 28 { 29 ll i,j,k,l; 30 for(i=0;i<=32;i++){ 31 if(pow(2,i)>M) break; 32 for(j=0;j<=32;j++){ 33 if(pow(2,i)*pow(3,j)>M) break; 34 for(k=0;k<=32;k++) {//k++后,l 再次从0开始。 35 if(pow(2,i)*pow(3,j)*pow(5,k)>M) break; 36 for(l=0;l<=32;l++){ 37 if(pow(2,i)*pow(3,j)*pow(5,k)*pow(7,l)>M) break;//在这里跳出才可以继续循环 38 a[cnt++] = pow(2,i)*pow(3,j)*pow(5,k)*pow(7,l); 39 } 40 } 41 } 42 } 43 sort(a,a+cnt); 44 } 45 int main() 46 { 47 48 init(); 49 scanf("%d",&t); 50 while(t--){ 51 scanf("%lld",&n); 52 printf("%lld\n",a[lower_bound(a,a+cnt,n)-a]); 53 } 54 return 0; 55 }
分类:
打表
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现