-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathbinary_search.cpp
More file actions
43 lines (39 loc) · 1.04 KB
/
binary_search.cpp
File metadata and controls
43 lines (39 loc) · 1.04 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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int long long
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';
#define db long double;
using pll = pair < ll, ll >;
#define scan(a, n) for(int i = 0; i < n; i++)cin >> a[i];
#define rep(i,x,n) for(ll i=x ; i<n ; i++)
#define per(i,x,n) for( i=x ; i>n ; i--)
#define hell 1000000007
#define infl LLONG_MAX
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl //print with precision
#define tc(tt) \
ll tt; \
cin >> tt; \
while(tt--) // testcase
ll res(ll x, ll y, ll n, ll l, ll h) {
ll m=(l+h)/2;
while(l<=h) {
m=(l+h)/2;
ll paintings= m/x + m/y;
if(paintings>=n) h=m-1;
else l=m+1;
}
return m;
}
int main() {
tc(tt) {
ll x, y, n;
cin>>n>>x>>y;
if(x>y) swap(x, y);
if(n<=1) cout<<n*x<<endl;
else cout<<res(x, y, n-1, 0, x*n)+x<<endl;
}
}