#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
freopen("pyramid.in", "r", stdin);freopen("pyramid.out", "w", stdout);ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T; cin >> T;
while(T --)
{
int x, p, t;
cin >> x >> p;
t = floor(sqrt(x * x + x - 2 * p));
while((((x + t) * (x - t + 1)) / 2) - p >= t){t ++;}
cout << (((x + t) * (x - t + 1)) / 2) - p << "\n";
}return 0;}

粤公网安备44010602015266号
共 11 条回复
666