Cod sursa(job #2163677)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 12 martie 2018 19:24:21
Problema GFact Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <cstdio>
#include <cmath>

using namespace std;

inline int cmmdp(int x)
{
    int d = 2;
    int e,lim;
    lim = (int)sqrt((double)x);
    while(d <= lim && x > 1)
    {
        e = 0;
        while(x % d == 0)
        {
            e++;
            x /= d;
        }
        d++;
    }
    if(x > 1)
        return x;
    return d;
}

inline int FactExp(int f,int val)
{
    int d;
    int s = 0;
    d = val;
    while(d <= f)
    {
        s += (int)(f/d);
        d *= val;
    }
    return s;
}

int main()
{
    freopen("gfact.in","r",stdin);
    freopen("gfact.out","w",stdout);
    int n,e;
    scanf("%d%d",&n,&e);
    int x = cmmdp(n);
    int st,dr,med;
    st = 1;
    dr = 2000000000;
    int ans = 0;
    while(st <= dr)
    {
        med = (st+dr)/2;
        int val = FactExp(med,x);
        if(val >= e){
            dr = med-1;
            ans = med;
        }
        else
        {
            st = med+1;
        }
    }
    printf("%d",ans);
    return 0;
}