题目链接:
2016 ACM/ICPC Asia Regional Qingdao Online HDU 5878 I Count Two Three
题意概括:
求可以写成 (a, b, c, d是非负整数),并且不大于 n 的最小整数。
数据范围:
,
题解分析:
先预处理打表,求出所有可能的组合。在每次查询的时候,二分查找即可。
由于数据范围是 ,故上限的值为
, 打表时 dfs 到上限就可以停止。
并且根据
,可以求出每层循环的次数。
二分用 lower_bound函数 实现即可。
AC代码:
#include <stdio.h>
#include <algorithm>
using namespace std;
const int MAXN = 7e3;
typedef long long ll;
ll num[MAXN];
ll pow(int x, int n) {
if (n == 0) return 1;
ll res = pow(x * x, n / 2);
if (n & 1) res = res * x;
return res;
}
int main () {
int cnt = 0;
for (int i = 0; i < 11; i ++) {
for (int j = 0; j < 14; j ++) {
for (int i2 = 0; i2 < 20; i2 ++) {
for (int j2 = 0; j2 < 31; j2 ++) {
ll temp = pow(7,i) * pow(5,j) * pow(3,i2) * pow(2,j2);
if (temp > 2e9) break;
else
num[cnt ++] = temp;
}
}
}
}
int T;
sort(num, num + cnt);
scanf("%d", &T);
while (T --) {
int n;
scanf("%d", &n);
ll *ans = lower_bound(num, num + cnt, n);
printf ("%lld\n", *ans);
}
}
I Count Two Three
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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 which a,b,c,d are non-negative integers.
At recent dinner parties, we call the integers with the form "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