Cod sursa(job #3330697)

Utilizator CalinPaun29Paun Calin CalinPaun29 Data 21 decembrie 2025 13:06:14
Problema GFact Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.24 kb
//#pragma GCC optimize("O3, Ofast, unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    ifstream cin("gfact.in");
    ofstream cout("gfact.out");
    int p, q;
    cin>>p>>q;
    map<int, int> mp;
    while(p%2==0)
    {
        mp[2]+=q;
        p/=2;
    }
    int div=3;
    while(p>1 && div<=p)
    {
        while(p%div==0)
        {
            mp[div]+=q;
            p/=div;
        }
        div+=2;
    }
    int l=-1, r=6*1e13, mid;
    while(l<r-1)
    {
        mid=(l+r)/2;
        int ok2=0;
        for(auto it:mp)
        {
            int x=it.first, y=it.second;
            int nr=0, ok=0;
            for(int i=x; i<=mid; i+=x)
            {
                int cc=i;
                while(cc>1 && cc%x==0)
                {
                    nr++;
                    cc/=x;
                }
                if(nr>=y)
                {
                    ok=1;
                    break;
                }
            }
            if(ok==0)
            {
                ok2=1;
                break;
            }
        }
        if(ok2==0)
            r=mid;
        else
            l=mid;
    }
    cout<<r;
    return 0;
}