Cod sursa(job #2082708)

Utilizator syndicat3albu alex syndicat3 Data 6 decembrie 2017 18:38:18
Problema GFact Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int ndp;
int d[15],p[15];
long long x,y;

long long putere(long long n, int p )
{
    long long nr=0;
    while (n>=p)
    {
        nr+=(n/=p);
    }
    return nr;
}

bool sedivide(long long n)
{

    for (int i=0; i<ndp; i++)
    {
        if(putere(n,d[i])<p[i]*y)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    in>>x>>y;
    ndp=0;
    int a=2;
    while(a*a<=x)
    {
        if(x%a==0)
        {
            d[ndp]=a;
            while(x%a==0)
            {
                p[ndp]++;
                x/a;
            }
            ndp++;
        }
        a++;
    }
    if(x>1)
    {
        d[ndp]=x;
        p[ndp]=1;
        ndp++;
    }

    long long r,pas;
    r=0;
    pas=1LL<<45;
    while (pas!=0)
    {
        if(!sedivide(r+pas))
        {
            r+=pas;
        }
        pas/=2;
    }
    r++;
    out << r;
    in.close();
    out.close();
    return 0;
}