QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#725606 | #6694. Math Problem | frogman | WA | 58ms | 3596kb | C++14 | 824b | 2024-11-08 19:03:14 | 2024-11-08 19:03:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read(){
int x=0;
char ch=getchar();
while(!isdigit(ch)){
ch=getchar();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=getchar();
}
return x;
}
void out(__int128 x){
if(x>9){
out(x/10);
}
putchar(x%10+'0');
}
inline void solve(){
__int128 n,k,m,a,b;
n=read();k=read();m=read();a=read();b=read();
if(n%m==0){
cout<<"0\n";
return;
}
if(k==1){
cout<<"-1\n";
return;
}
__int128 ans=4e18;
__int128 s=0;
while(n){
__int128 now=s;
__int128 x=n,y=n;
while(y<2e18){
now+=a;
x*=k;y=y*k+k-1;
if(y/m-(x-1)/m){
ans=min(ans,now);
}
}
n/=k;
s+=b;
}
ans=min(ans,s);
out(ans);
cout<<'\n';
}
int main(){
int T;
cin>>T;
while(T--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
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: 58ms
memory: 3596kb
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 10051 ...
result:
wrong answer 127th numbers differ - expected: '21176', found: '63528'