2015年2月28日 星期六

[UVA] 12428 - Enemy at the Gates

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int t,n,m,x,y,i,j;
    scanf("%lld",&t);
    while(t--){
        scanf("%lld%lld",&n,&m);
        long long int L=0,R=n+1,M;
        while(L+1!=R){
            M=(L+R)/2;
            if(M*(M-1)/2+n-M>=m) R=M;
            else L=M;
        }
        printf("%lld\n",n-R);
    }
}

沒有留言:

張貼留言