Cod sursa(job #3173985)

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

using namespace std;

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

int P, Q;

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

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