14行 B题

danielhaohuang 2026-10-04 14:16:12

#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;}

共 11 条回复

kingkong

666