Source Code
#include<bits/stdc++.h>
using namespace std;
#define pb  					push_back
#define mp 						make_pair
#define all(v) 					((v).begin()) ,((v).end())
#define let(o,v)				memset(o,v,sizeof (o))
typedef long long 				ll;
typedef vector<int>				vi;
typedef vector<vi>				vvi;
typedef vector<string>			vs;
const int N = (int)10000007;
const ll MOD = 1e9 + 7;
const int oo = (int)1e9;
const ll OO = (ll)1e18;
const double PI = acos(-1.0);


bool isprime(int n) {
    if (n <= 1)
        return 0;
    for (int i = 2; i*i <= n; i++)
        if (n%i == 0)
            return false;
    return 1;
}
ll intlog(ll base, ll x) {
    return (log(x) / log(base));
}
bool prime[N];
vector<int> next_primee;
void primee()
{
    let(prime, 1);
    for (int p = 2; p*p <= N; p++)
    {

        if (prime[p] == true)
        {
            for (int i = p * 2; i < N; i += p)
                prime[i] = false;
        }
    }

}
string decToBinary(ll n)
{
    string z = "";
    int i = 0;
    while (n > 0) {

        z += (n % 2) + 48;
        n = n / 2;
        i++;
    }
    reverse(all(z));
    return z;
}
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}
ll power(ll x, ll y)
{
    ll temp;

    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp* temp;
    else
        return x * temp* temp;
}
ll n , k ,d;
bool can(ll mid){
    return (mid / k) + (mid / d) >= n;
}
int main() {
    cin>> n >>k >>d;
    ll l = 1, r = 1e18;
    ll ans = 1e18;
    while(l<=r){
        ll mid = (l+r)/2;
        if(can(mid)){
            ans = mid;
            r = mid - 1;
        }
        else {
            l = mid +1;
        }
    }
    cout<<ans;
    return 0;
}
Copy
Hurry up hamzah_alghanem
GNU G++17
0 ms
764 KB
Accepted