Cod sursa(job #3003420)

Utilizator Mihai_AritonMihai Ariton Mihai_Ariton Data 15 martie 2023 18:41:38
Problema GFact Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct desc
{
    int x, y;
}v[100005];
int k=0;
bool verif(int fact)
{
    int nr, s;
    for(int i=1; i<=k; i++)
    {
        nr=v[i].x;s=0;
        while(nr<=fact)
        {
            s=s+fact/nr;
            nr=nr*v[i].x;
        }
        if(s<v[i].y)return 0;
    }
    return 1;
}
signed main()
{
    ifstream cin("gfact.in");
    ofstream cout("gfact.out");
    
    int a, b, d=2, p, st=1, dr=1e18, mij, ans;
    cin>>a>>b;
    while(d*d<=a)
    {
        p=0;
        while(a%d==0)
        {
            p++;
            a/=d;
        }
        if(p>0)
        {
            k++;
            v[k].x=d;
            v[k].y=b*p;
        }
        d++;
    }
    if(a>1)
    {
        k++;
        v[k].x=a;
        v[k].y=b;
    }
    //verif(4);return 0;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        if(verif(mij)==1)
        {
            ans=mij;
            dr=mij-1;
        }
        else
        st=mij+1;
    }
    cout<<ans;

    return 0;
}