QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#624440 | #6694. Math Problem | LmR308 | WA | 21ms | 3844kb | C++17 | 1.5kb | 2024-10-09 15:51:24 | 2024-10-09 15:51:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int128 __int128_t
#define int long long
#define PII pair<int, int>
#define PDD pair<double, double>
#define fi first
#define se second
#define lowbit(x) x & -x
#define all(x) x.begin(), x.end()
#define INF 0x3f3f3f3f3f3f3f3f
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define ull unsigned long long
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 10, M = 5e6 + 10, mod = 998244353;
const double eps = 1e-8;
int t, n, m, k;
string sr;
void solve() {
int a, b;
cin >> n >> k >> m >> a >> b;
vector<PII> te;
int temp = n, res = INF;
if (k == 1) {
if (n % m == 0) cout << 0 << "\n";
else cout << -1 << "\n";
return;
}
if (n % m == 0) {
cout << 0 << "\n";
return;
}
int step = 0;
while (temp != 0) {
temp /= k;
step += b;
if (temp == 0) res = min(res, step);
else te.push_back({temp, step});
}
for (int i = 0; i < te.size(); i++) {
int l = te[i].first, r = te[i].first, stp = te[i].second;
while (true) {
int num = l / m;
int ri = (num + 1) * m;
if (l % m == 0 || ri <= r) {
res = min(res, stp);
break;
}
l = l * k, r = r * k + k - 1;
stp += a;
}
}
cout << res << "\n";
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
//cout.setf(ios::fixed), cout.precision(8);
t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3844kb
input:
4 101 4 207 3 5 8 3 16 100 1 114 514 19 19 810 1 1 3 1 1
output:
11 2 0 -1
result:
ok 4 number(s): "11 2 0 -1"
Test #2:
score: -100
Wrong Answer
time: 21ms
memory: 3620kb
input:
100000 9 5 7 7674 78731 4 3 4 58482 93736 1 4 3 42396 22960 6 2 2 4534 73466 5 7 7 56203 19376 1 7 10 77129 84094 8 3 3 72793 89258 10 10 3 94847 42455 7 4 7 79273 90760 2 7 3 78496 99140 4 4 9 47018 14651 3 7 8 60936 4453 8 6 4 57267 6293 8 7 3 81697 99664 2 10 10 3935 30951 8 9 7 91391 70670 5 8 8...
output:
86405 0 22960 0 19376 84094 162051 84910 0 99140 29302 4453 0 181361 30951 70670 66652 79451 0 0 0 115590 30063 0 57852 31894 160437 17263 21111 72620 27536 0 7306 129702 24753 57559 73441 121546 58842 38743 102738 38963 61730 0 42044 55519 63574 97592 87881 1674 58973 8130 0 46609 98722 11696 7808 ...
result:
wrong answer 1st numbers differ - expected: '7674', found: '86405'