QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#810904#9864. Coinnice333WA 1ms3708kbC++231.3kb2024-12-12 13:06:272024-12-12 13:06:29

Judging History

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

  • [2024-12-12 13:06:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3708kb
  • [2024-12-12 13:06:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,k,C = 0;
int check(int m){
    int res=0;
    while(m>k){
        C++;
        int sub=(m+k-1ll)/k;
        int next=(sub-1ll)*k;
        int t = (m-next)/sub;
        res+= t ;
        m-=t*sub;
        if(m>next){
            m-=sub;
            res++;
        }
        //cout<<m<<" "<<res<<"\n";
    }
    res+=m-1ll;
    return res;
}
void solve() {
    // int n,k;cin>>n>>k;
    // int m=1;
    // while(true){
    //     int p=(m%(k-1ll)==0)?(m/(k-1ll)):(m/(k-1ll)+1ll);
    //     int add=p;
    //     p=p*k-p;
    //     int m1=(p-m)/add*add+m;
    //     if(m1==m)m1+=add;
    //     if(m1>n){
    //         cout<<(n-m)/add*add+m<<"\n";
    //         return;
    //     }
    //     m=m1;
    // }



    cin>>n>>k;
    if(n<=k)cout<<n<<"\n";
    else{
        int l=n-(n+k-1ll)/k+1ll,r=n,p=check(n)-1ll;
        while(l<r){
            int mid=(l+r+1ll)>>1;
            if(check(mid)<=p)l=mid;
            else r=mid-1;
        }
        cout<<l+1ll<<"\n";
    }
    // n=1919810;k=114514;
    // cout<<check(1)<<" "<<check(n)<<"\n";
}
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t=1;
    cin>>t;
    while (t--) solve();

    std::cerr<<C/1e8<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3708kb

input:

4
6 2
8 3
10000 2
1919810 114514

output:

5
8
8192
1919805

result:

wrong answer 1st numbers differ - expected: '4', found: '5'