这题显然优先找大的
直到找不下去了,判断无解或者拿个与需要的分水器相等的(显然有)
因为一个k的分水器只能增加k-1条通道
所以列方程
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iostream>
using namespace std;
#define MAXN (1000000000000000000)
#define MAXK (1000000000)
long long n,k;
long long bin_s(long long l,long long r)
{
if (n==1) return 0;
while (r-l>1)
{
long long m=(l+r)/2;
if ((m+k-1)*(k-m)>2*(n-1)) l=m;
else r=m;
}
if ((l+k-1)*(k-l)>2*(n-1)) l=r;
if ((l+k-1)*(k-l)<2*(n-1)) l--;
if (l==0) return -1;
return k-l;
}
int main()
{
cin>>n>>k;
cout<<bin_s(1,k-1)<<endl;
return 0;
}