Cod sursa(job #1593211)

Utilizator armandpredaPreda Armand armandpreda Data 8 februarie 2016 13:37:38
Problema GFact Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>

using namespace std;

ifstream cin("gfact.in");
ofstream cout("gfact.out");

int n, put;
long long caut_bin(int x, int px)
{
    long long st=0, dr=1ll*x*px, mj;
    while(st<=dr)
    {
        mj=(st+dr)/2;
        int cur=0;
        long long cop=x;
        while(cop<=mj)
        {
            cur+=mj/cop;
            cop*=x;
        }
        if(cur<px)
            st=mj+1;
        else
            dr=mj-1;
    }
    return st;
}
int main()
{
    cin>>n>>put;
    long long ans=0;
    int f=2;
    while(n>1)
    {
        if(f*f>n) f=n;
        int cur=0;
        while(n%f==0)
        {
            cur++;
            n/=f;
        }
        long long val=caut_bin(f, cur*put);
        if(ans<val) ans=val;
        f++;
    }
    cout<<ans;
    return 0;
}