二分穷举寻找正好吃完的那天,因为那天后被吃完,那天没被吃完,所以用二分搜索
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long int ll;
ll m,n;
int main()
{
scanf("%lld%lld",&n,&
m);
if(m>=
n)
printf("%lld\n",n);
else
{
ll cnt=n-
m;
ll l=
1,r=3e9+
7;
while(l<=
r)
{ ll mid=(l+r)/
2;
if((mid+
1)*mid/
2>=cnt)
//神奇的递加数列求和公式
r=mid-
1;
else
l=mid+
1;
}
ll day=m+
l;
printf("%lld\n",day);
}
return 0;
}
转载于:https://www.cnblogs.com/Wangwanxiang/p/6696755.html