QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#724259 | #6694. Math Problem | crazymoon | WA | 25ms | 3696kb | C++20 | 893b | 2024-11-08 11:22:37 | 2024-11-08 11:22:37 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const double eps = 1e-8;
void solve() {
int n, k, m, a, b, res = 1e15, cur = 0;
cin >> n >> k >> m >> a >> b;
if(n % m == 0) {
cout << 0 << '\n';
return ;
}
if(k == 1) {
cout << -1 << '\n';
return ;
}
while(n) {
int tmp = cur, len = 1, l = n % m, r = n % m;
while(len < m && (l < r || l == r && l)) {
tmp += a;
len *= k;
l = l * k % m;
r = (r * k % m + k - 1) % m;
}
res = min(res, tmp);
n = n / k;
cur += b;
}
res = min(res, cur);
cout << res << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1; cin >> t;
while(t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3696kb
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: 25ms
memory: 3616kb
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:
7674 0 22960 0 19376 77129 72793 84910 0 78496 29302 4453 0 81697 3935 70670 36522 21244 0 0 0 100934 30063 0 57852 31894 72016 6193 9486 2516 27536 0 7306 73625 11302 13802 41343 50014 58015 38743 65165 38963 26747 0 42044 45733 63574 69321 34196 1674 27200 8130 0 46609 53621 11696 7808 4630 40204 ...
result:
wrong answer 59th numbers differ - expected: '10051', found: '40204'