Cod sursa(job #3191900)

Utilizator AlexandruCorneaCornea Alexandru Mihai AlexandruCornea Data 10 ianuarie 2024 21:13:21
Problema GFact Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin ("gfact.in");
ofstream fout ("gfact.out");
#define DR (1LL << 46)
int d[10],p[10],ct,y;
long long putere(long long n, int d)
{

    long long nr = 0;
    while (n >= d)
    {
        nr += (n /= d);
    }
    return nr;
}
bool se_divide(long long n)
{
    for (int i=1; i<=ct; i++){

 long long p_fact = putere(n, d[i]);
        if (p_fact < p[i] * y)
            return false;}
    return true;
}
int main()
{
 int  x;
    fin>>x>>y;
   int a=2,b;

    while(x>a*a)
    {

        b = 0;
        while(x % a == 0)
        {
            ++b;
            x /= a;
        }

        if(b)
        {
            ct++;
            d[ct]=a;
            p[ct]=b;
        }
        ++ a;



    }
    if (x)
    {
          ct++;
            d[ct]=x;
            p[ct]=1;
    }

    long long st=1,dr=DR,rez=dr+1;

while (st <= dr)
    {

        long long m = (st + dr) / 2;

        if (se_divide(m))
        {
            rez = m;
            dr = m - 1;
        }
        else
        {
            st = m + 1;
        }
    }
    fout<<rez;

return 0;
}