Cod sursa(job #2073660)

Utilizator ioana.jianuIoana Jianu ioana.jianu Data 23 noiembrie 2017 15:18:42
Problema GFact Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

long long p;

long long fact(long long x){
    long long suma=0,putere=p;
    while(x/putere>0){
        suma+=x/putere;
        putere*=p;
    }
    return suma;
}

int main(){

    freopen("gfact.in","r",stdin);
    freopen("gfact.out","w",stdout);

    long long putere,s,q;

    scanf("%lld%lld",&p,&q);

    putere=1LL<<30;
    s=0;
    while(putere>0){
        if(fact(s+putere)<=q-1)
            s+=putere;
        putere/=2;
    }

    printf("%lld",s+1);

    return 0;
}