QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#805390 | #9864. Coin | YWKM | WA | 0ms | 3616kb | C++20 | 831b | 2024-12-08 16:25:14 | 2024-12-08 16:25:15 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
using ll=long long ;
void solve(){
ll n,k;
cin>>n>>k;
if(sqrt(n)>=k){
ll x=1;
ll pre=1;
while(x<=n){
pre=x;
x=x+(x+k-2)/(k-1);
}
cout<<pre<<'\n';
}
else{
ll x=1;
while(x<n){
ll t=(x+k-2)/(k-1);
ll y=t*(k-1);
if(y==x){
y+=k-1;
}
if(y>=n){
x+=t*((n-x)/t);
break;
}
x+=(y-x+t-1)/t*t;
}
cout<<x<<'\n';
}
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(0);
cout.tie(nullptr)->sync_with_stdio(0);
int t;
cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
4 6 2 8 3 10000 2 1919810 114514
output:
4 6 8192 1919800
result:
wrong answer 2nd numbers differ - expected: '8', found: '6'