QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#290531 | #4613. 避难所 | MoRanSky | 100 ✓ | 6ms | 4464kb | C++23 | 2.3kb | 2023-12-25 05:26:12 | 2023-12-25 05:26:13 |
Judging History
answer
// Skyqwq
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long LL;
typedef pair<int, int> PII;
template <typename T> void inline read(T &x) {
x = 0; int f = 1; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') { f = -1; } s = getchar(); }
while (s >= '0' && s <= '9') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
template <typename T> bool inline chkMin(T &x, T y) { return y < x ? x = y, 1 : 0; }
template <typename T> bool inline chkMax(T &x, T y) { return y > x ? x = y, 1 : 0; }
int b;
const int N = 1e5 + 5;
bool st[N];
set<int> s;
bool inline chk(LL x, LL w) {
LL pw = 1, z = 0;
for (int i = b - 1; i > 1; i--) {
while (w % i == 0) {
z += pw * i;
pw *= b;
w /= i;
if (z > x) return 1;
}
}
return 0;
}
void inline out(LL x) {
vector<int> w;
while (x) w.pb(x % b), x /= b;
reverse(w.begin(), w.end());
printf("%lu", w.size());
for (int v: w) printf(" %d", v);
puts("");
}
void wk() {
int o = pow(b, 1/3.0);
while (1ll * o * o * o >= b) o--;
auto t = s.upper_bound(o);
int A = -1;
if (t != s.begin()) --t, A = *t;
int B = -1;
o = pow(b,1/2.0);
while (1ll * o * o <= b) o++;
t = s.lower_bound(o);
if (t != s.end() && *t < b) B = *t;
//cout << A << "??" << B << endl;
if (A != -1 && B != -1) {
LL z = A * B;
if (z < b) {
//cout << z << "??\n";
if (chk(1ll * z * b * b + 1ll * z * b + z, 1ll * z * z * z)) {
out(1ll * z * b * b + 1ll * z * b + z);
//puts("ok");
return;
}
}
}
for (int i = b - 1; i >= 2; i--) {
LL u = (LL)i * b * b + (LL)i * b + i;
if (st[i] && chk(u, (LL)i * i * i)) {
out(u);
return;
}
}
if (b < 100) {
for (int i = 1; i < b; i++) {
if (!st[i]) continue;
for (int j = i+ 1; j < b; j++) {
if (!st[j]) continue;
LL u = (LL)i * b * b + (LL)j * b + j;
if (chk(u, (LL)i * j * j)) {
out(u);
return;
}
}
}
}
puts("-1");
}
int main() {
for (int i = 2; i < N; i++) {
if (!st[i]) {
s.insert(i);
//cout << i << "??\n";
for (int j = i + i; j < N; j += i) st[j] = 1;
}
}
//freopen("3.in", "r", stdin);
int T; read(T);
while (T--) {
read(b);
wk();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 30
Accepted
time: 2ms
memory: 4460kb
input:
30 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
output:
-1 -1 -1 -1 -1 -1 3 6 6 6 -1 -1 -1 3 9 10 10 3 9 10 10 3 9 10 10 -1 3 4 10 10 3 4 10 10 3 4 10 10 3 4 10 10 3 4 14 14 3 4 14 14 3 4 14 14 3 4 14 14 3 18 18 18 3 18 18 18 3 18 18 18 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21
result:
ok ok (30 test cases)
Test #2:
score: 40
Accepted
time: 0ms
memory: 4464kb
input:
98 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
output:
-1 -1 -1 -1 -1 -1 3 6 6 6 -1 -1 -1 3 9 10 10 3 9 10 10 3 9 10 10 -1 3 4 10 10 3 4 10 10 3 4 10 10 3 4 10 10 3 4 14 14 3 4 14 14 3 4 14 14 3 4 14 14 3 18 18 18 3 18 18 18 3 18 18 18 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 2...
result:
ok ok (98 test cases)
Test #3:
score: 30
Accepted
time: 6ms
memory: 4416kb
input:
200 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
output:
-1 -1 -1 -1 -1 -1 3 6 6 6 -1 -1 -1 3 9 10 10 3 9 10 10 3 9 10 10 -1 3 4 10 10 3 4 10 10 3 4 10 10 3 4 10 10 3 4 14 14 3 4 14 14 3 4 14 14 3 4 14 14 3 18 18 18 3 18 18 18 3 18 18 18 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 21 3 21 21 2...
result:
ok ok (200 test cases)
Extra Test:
score: 0
Extra Test Passed