找规律, 容易发现 当第m 天后 粮仓容量开始减少, 每天递增的数目是 以公差为1的等差数列, 前n项和为 n*(n+1)/2 所以
通俗的讲就是 二分查找 Sn>= n-m 即为结果;
#include#include #include #include #include #include #include #include #include #include #include using namespace std;typedef long long ll;const double PI=acos(-1); const int INF=0x3f3f3f3f; const double esp=1e-6; const int maxn=1e18+2; const int MOD=1e9+7;#define mem(a,b) memset(a,b,sizeof(a))#define findx(x) lower_bound(b+1,b+1+bn,x)-bll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}int main(){ ll n,m; while(~scanf("%I64d %I64d",&n,&m)) { ll ans; ll mid; ll le=0,ri=maxn; if(n<=m) { ans=n; printf("%I64d\n",ans); continue; } while(le =n-m) { ri=mid; } else le=mid+1; } printf("%I64d\n",le+m); }}//570441179141911871 511467058318039545