Cod sursa(job #3173986)

Utilizator Alexbora13Bora Ioan Alexandru Alexbora13 Data 24 noiembrie 2023 08:58:45
Problema GFact Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("gfact.in");
ofstream fout("gfact.out");

long long P, Q;

int ok(long long x)
{
    long long div = x/P;
    if(div*(div+1)/2>=Q)
        return 1;
    return 0;
}

int main()
{
    fin >> P >> Q;
    long long st = 1, dr = INT_MAX;
    while(st<=dr)
    {
        long long mij = (st+dr)/2;
        if(ok(mij)==1)
            dr = mij-1;
        else
            st = mij+1;
    }
    fout << st;
    return 0;
}