#include<bits/stdc++.h>
#define FOR(i,a,b,k) for (ll i=a;i<=b;i+=k)
#define FORD(i,a,b,k) for (ll i=a;i>=b;i-=k)
#define pb(i) push_back(i)
#define ll long long int
#define MOD 1e9+7
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define hay_goi_minh_la_long_xau_trai_hoc_dot_hay_chep_bai_ban_di ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define hay_goi_minh_la_long_dep_trai_di_vi_minh_xau_trai_vai_beep() int main()
using namespace std;
template < typename T> ll power( T & a, const T & b) { ll res = 1 , x = a, y = b; while ( y) { if ( y & 1 ) res * = x; x = x * x; y>>= 1 ; } ; return res; }
template < typename T> ll modpower( T & a, const T & b, const T & m) { ll res = 1 , x = a, y = b; x % = m; while ( y) { if ( y & 1 ) res * = x % m; x = x * x % m; y>>= 1 ; } ; return res; }
inline ll readll( ) { char c; while ( c= getchar ( ) ,c! = '-' && ( c< '0' || c> '9' ) ) ; bool sign= ( c== '-' ) ; if ( sign) c= getchar ( ) ; ll n= c- '0' ; while ( c= getchar ( ) ,c>= '0' && c<= '9' ) n= 10 * n+ c- '0' ; return ( ! sign) ? n: - n; }
inline string readstring( ) { char c; while ( c= getchar ( ) ,c== ' ' || c== '\n ' || c== '\t ' ) ; string s( { c} ) ; while ( c= getchar ( ) ,c! = EOF && c! = ' ' && c! = '\n ' && c! = '\t ' ) s+ = c; return s; }
// het phan lon xao roi, gio moi vao code chinh
ll t,a,b,n; // bien xu ly nhap
ll lcd,mid; // bien xu ly chat nhi phan
ll T,dem; // bien cho xu ly chu ky toan
bool kt( ll x)
{
if ( x/ a+ x/ b- x/ lcd< n) return 0 ;
return 1 ;
}
void loading( )
{
ll l= dem* lcd,r= ( dem+ 1 ) * lcd;
while ( l< r)
{
mid= ( l+ r) / 2 ;
if ( ! kt( mid) ) l= mid+ 1 ; else r= mid;
}
cout << l<< '\n ' ;
}
hay_goi_minh_la_long_dep_trai_di_vi_minh_xau_trai_vai_beep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