就可以得到一个表达式,二分求值
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define eps 1e-9
#define PI 3.141592653589793
#define bs 1000000007
#define bsize 256
#define MEM(a) memset(a,0,sizeof(a))
typedef long long ll;
using namespace std;
ll n,m;
int check(ll x)
{
ll s=n-(x+1)*x/2-m;
// printf("%lld\n",s);
if(s>0)
return 1;
return 0;
}
int main()
{
ll le,ri,mid,ans;
scanf("%lld %lld",&n,&m);
if(n<=m)
printf("%lld\n",n);
else
{
le=0,ri=1e10;
while(le<=ri)
{
mid=(le+ri)>>1;
if(check(mid))
{
le=mid+1;
ans=mid;
}
else
{
ri=mid-1;
}
}
printf("%lld\n",m+ans+1);
}
return 0;
}