-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1352C.cpp
More file actions
56 lines (52 loc) · 1.11 KB
/
Copy path1352C.cpp
File metadata and controls
56 lines (52 loc) · 1.11 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
#include "bits/stdc++.h"
using namespace std;
#define ll long long
void solve() {
ll n,k; cin>>n>>k;
ll sol;
if (n>k) {
sol=k;
} else {
ll l=1,r=k*2,ans=0;
while (l<=r) {
ll m=l+(r-l)/2;
if (m-(m/n)>=k) {
ans=m;
r=m-1;
} else {
l=m+1;
}
}
}
cout<<sol<<"\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tests; cin >> tests;
while (tests-- > 0) solve();
return 0;
}
// its also possible to do binary search over the segments which always have (n-1) non-dividable numbers since we multiply with n
// ll find(ll l, ll r, ll k, ll n) {
// while (l<=r) {
// ll m=l+(r-l)/2;
// if ((n-1)*m>=k) {
// r=m-1;
// } else {
// l=m+1;
// }
// }
// return k-r*(n-1)+r*n;
// }
// void solve() {
// ll n,k; cin>>n>>k;
// ll sol;
// if (n>k) {
// sol=k;
// } else {
// ll l=1,r=(ll)1e9;
// sol = find(l, r, k, n);
// }
// cout<<sol<<"\n";
// }