I Count Two Three
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 649 Accepted Submission(s): 332
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
不懂得可以搜下丑数的求法。
#pragma comment(linker,"/STACK:124000000,124000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#define lson i<<1
#define rson i<<1|1
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define scanfi(a) scanf("%d",&a)
#define scanfs(a) scanf("%s",a)
#define scanfl(a) scanf("%I64d",&a)
#define scanfd(a) scanf("%lf",&a)
#define key_val ch[ch[root][1]][0]
#define eps 1e-7
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxn = 10000;
int dp[maxn];
template<class T> void read(T&num)
{
char CH;
bool F=false;
for(CH=getchar(); CH<'0'||CH>'9'; F= CH=='-',CH=getchar());
for(num=0; CH>='0'&&CH<='9'; num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p)
{
if(!p)
{
puts("0");
return;
}
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
}
int main()
{
int T,n;
scanf("%d",&T);
dp[0] = 1;
int d,d2,d3,d5,d7;
d = 1;
d2 = d3 = d5 = d7 = 0;
while(dp[d-1] < 1e9)
{
int ans;
ans = min(dp[d2]*2, dp[d3]*3);
ans=min(ans,dp[d7]*7);
ans=min(ans,dp[d5]*5);
if (ans == dp[d2]*2)++d2;
if (ans == dp[d3]*3)++d3;
if (ans == dp[d5]*5)++d5;
if (ans==dp[d7]*7)++d7;
dp[d++] = ans;
}
while (T--)
{
scanf("%d",&n);
int pos =lower_bound(dp,dp+5194,n)-dp;
printf("%d\n",dp[pos]);
}
return 0;
}