QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#805390#9864. CoinYWKMWA 0ms3616kbC++20831b2024-12-08 16:25:142024-12-08 16:25:15

Judging History

你现在查看的是最新测评结果

  • [2024-12-08 16:25:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-12-08 16:25:14]
  • 提交

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'