QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368348 | #4366. Forever Young | cciafrino# | TL | 80ms | 3524kb | C++20 | 1.3kb | 2024-03-27 01:17:36 | 2024-03-27 01:17:36 |
Judging History
answer
#include<bits/stdc++.h>
int main() {
using namespace std;
cin.tie(nullptr)->sync_with_stdio(false);
using i64 = int64_t;
i64 N, L; cin >> N >> L;
i64 ans = 0;
auto test = [&](i64 B) -> i64 {
if (B <= 1) return -1;
i64 cur = N;
i64 val = 0;
vector<i64> digs;
while (cur) {
if (cur % B >= 10) return -1;
digs.push_back(cur % B);
cur /= B;
}
int cnt = int(digs.size());
bool ok = false;
if (cnt <= 10) {
for (int d = cnt-1; d >= 0; --d) {
val = 10 * val + digs[d];
}
if (val >= L) ok = true;
} else ok = true;
return ok ? B : -1;
};
auto check = [&](double m, i64 x, i64 y, i64 d) -> bool {
if (m * m * d + m * x + y >= 2e18) return false;
return (m * m * d + m * x + y <= N);
};
for (int x = 2; x <= 5e5; ++x) ans = max(ans, test(x));
for (int x = 1; x <= N; ++x) {
for (int y = 0; y <= N; ++y) {
i64 K = (N - y)/x;
ans = max(ans, test(K));
}
}
for (int d = 1; d <= 9; ++d) {
for (int x = 0; x <= 9; ++x) {
for (int y = 0; y <= 9; ++y) {
i64 mi = 0, ma = 2e18;
while (ma - mi > 1) {
i64 md = (mi + ma) / 2;
double m = md;
(check(m, x, y, d) ? mi = md : ma = md);
}
ans = max(ans, test(mi));
}
}
}
cout << ans << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3488kb
input:
32 20
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 80ms
memory: 3524kb
input:
2016 100
output:
42
result:
ok single line: '42'
Test #3:
score: -100
Time Limit Exceeded
input:
1000000000000000000 10