-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblems-H.cpp
More file actions
75 lines (69 loc) · 1.66 KB
/
Copy pathproblems-H.cpp
File metadata and controls
75 lines (69 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define pb push_back
#define pi pair<ll,ll>
#define F first
#define S second
#define OUTRET(...) { OUT(__VA_ARGS__); return; }
#define OUT(...) cout << __VA_ARGS__ << '\n'
#define dbg(x) cout <<#x<<": "<<x<< ln;
#define all(x) (x).begin(), (x).end()
#define yes cout<<"YES"<<ln;
#define no cout<<"NO"<<ln;
#define sz(v) ((int)((v).size()))
#define ln '\n'
const ll INF = 1000000000;
const ll MOD = 1e9 + 7;
const ll M = 1e6 + 8432;
const ll N = 2e5 + 2000;
ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
template<class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<class T>
bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
void io() {
ios::sync_with_stdio(false);
cin.tie(NULL);
}
void solve() {
ll n,p , nx = 0 , k = 0 , ans = 0;
cin >> n >> p;
ll m = p;
while(p){
if(nx + p > n - 1) break;
nx += p;
k ++;
p --;
}
/*
idea is to get the number of steps you can do in n
and start in point with condition the last step should be the end
to get the max sum of numbers
*/
ll x = m - k + 1;
p = n;
while(n - x > 0 && k--){
p -= x;
ans += p;
ans%=MOD;
x += 1;
}
cout << (ans + n) % MOD << ln;
}
int main() {
io();
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif // ONLINE_JUDGE
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}