QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#138396 | #4366. Forever Young | PetroTarnavskyi# | WA | 1ms | 3416kb | C++17 | 1.3kb | 2023-08-11 17:27:51 | 2023-08-11 17:27:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (LL i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (LL i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const LL LINF = 1e18 + 4;
LL y, l;
__int128 f(int x, LL b)
{
__int128 res = 0;
__int128 o = 1;
while (x)
{
int k = x % 10;
res += k * o;
x /= 10;
if(x)
o *= b;
}
return res;
}
void check(int x)
{
LL L = 2, R = LINF;
while (L + 1 < R)
{
LL m = (L + R) / 2;
if (y < f(x, m))
R = m;
else
L = m;
}
if (f(x, L) == y)
{
cout << L << '\n';
exit(0);
}
}
bool ok(int b, LL x)
{
LL B = 1;
LL ans = 0;
while (B * b <= x) B *= b;
while (B)
{
LL k = x / B;
if (k > 9) return false;
ans *= 10;
ans += k;
x -= B * k;
B /= b;
}
return ans >= l;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> y >> l;
FOR (i, l, 1000)
{
check(i);
}
RFOR (b, 1e6 + 1, 2)
{
if (ok(b, y))
{
cout << b << '\n';
break;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3416kb
input:
32 20
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3416kb
input:
2016 100
output:
42
result:
ok single line: '42'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3368kb
input:
1000000000000000000 10
output:
999999999999999999
result:
wrong answer 1st lines differ - expected: '1000000000000000000', found: '999999999999999999'