QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#781890 | #6694. Math Problem | xixu | TL | 0ms | 3660kb | C++11 | 1.3kb | 2024-11-25 17:54:56 | 2024-11-25 17:54:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fup(a, b, c, d) for(int a = (b); a <= (c); a += (d))
#define fdo(a, b, c, d) for(int a = (b); a >= (c); a -= (d))
typedef long long ll;
typedef pair<int , int> PII;
typedef map<int , int> MII;
const int inf = 0x3f3f3f3f, N = 2e6 + 10, M = 4e5 + 10, mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, k, m, a, b;
void solve()
{
cin >> n >> k >> m >> a >> b;
if(k == 1) {
if(n % m == 0) {
cout << 0 << '\n';
}
else {
cout << -1 << '\n';
}
return ;
}
if(n % m == 0) {
cout << 0 << '\n';
return ;
}
int nu = 1, su;
int mi = INF;
while(n) {
su = nu * b;
nu ++;
n /= k;
int l = n, r = n, nn = 1;
while(1)
{
if(!(l % m)) break ;
int bl = l / m + 1;
if(bl * m <= r) break ;
nn = nn * k % m;
l = nn * n, r = (nn * (n + 1)) - 1;
su += a;
}
mi = min(mi, su);
}
cout << mi << '\n';
}
signed main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int _ = 1;
cin >> _;
while(_ --)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
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
Time Limit Exceeded
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...