-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCHFING.cpp
More file actions
55 lines (43 loc) · 836 Bytes
/
CHFING.cpp
File metadata and controls
55 lines (43 loc) · 836 Bytes
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
#include <bits/stdc++.h>
using namespace std;
long long t,n,k,d,last,first,N,ans;
typedef long long int ll;
ll mulmod(ll a, ll b)
{
ll mod=1000000007;
ll res = 0;
while (b > 0)
{
if (b % 2 == 1)
res = (res + a);
res%=mod;
a = (a * 2);
a%=mod;
b /= 2;
}
res%=mod;
return res;
}
int main()
{
int t;
cin>>t;
while(t--){
cin>>n>>k;
d=n-1;
last=k-1;
first=last%d;
N=(last-first)/d + 1;
ll z=last+first;
if(N%2==0){
N/=2;
}else{
z/=2;
}
ans= mulmod(N,(z));
//ans+=(first+last);
//ans%=1000000007;
cout<<ans%1000000007<<endl;
}
return 0;
}