QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#138399 | #4366. Forever Young | PetroTarnavskyi# | WA | 1ms | 3532kb | C++17 | 1.3kb | 2023-08-11 17:39:01 | 2023-08-11 17:39:03 |
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)
{
__int128 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: 3508kb
input:
32 20
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
2016 100
output:
42
result:
ok single line: '42'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3532kb
input:
1000000000000000000 10
output:
999999999999999999
result:
wrong answer 1st lines differ - expected: '1000000000000000000', found: '999999999999999999'