A. Split the Multiset

pure4knowledge / 2024-07-18 / 原文

原题链接

题解

想象一条 有 n 个 1 的链,每个 1 之间一条边相连,每次操作最多破坏 k-1 条链

code

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=114514;

ll func(ll n,ll k)
{
    if(n==1) return 0;
    if(n<=k) return 1;
    return func(n/k+(n%k!=0),k)+n/k+(n%k>1);
}

void solve()
{
    ll n,k;
    cin>>n>>k;
    ll cnt=0;
    while(n>k)
    {
        n-=k-1;
        cnt++;
    }
    if(n>1) cnt++;
    cout<<cnt<<'\n';
}
int main()
{
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--) solve();
    return 0;
}