Cod sursa(job #1155373)

Utilizator tudorv96Tudor Varan tudorv96 Data 26 martie 2014 21:03:10
Problema GFact Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <fstream>
using namespace std;

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

typedef unsigned long long ull;

ull p, q;

ull go(ull x) {
    ull ans = 0, pr = p;
    for (; pr <= x; pr *= p)
        ans += x / pr;
    return ans;
}

int main() {
    fin >> p >> q;
    ull sol = 1LL << 63;
    for (ull step = 1LL << 63; step; step >>= 1)
        if (go (sol - step) >= q)
            sol -= step;
    fout << sol;
}