Cod sursa(job #2634750)

Utilizator PredescuSebastianIonPredescu Sebastian Ion PredescuSebastianIon Data 12 iulie 2020 11:07:14
Problema Frac Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>

using namespace std;
ifstream f("frac.in");
ofstream g("frac.out");
long long c[20],n,k,x,y,p,u,m,pr;
int main()
{
    f>>n>>k;
    for(int i=2; i*i<=n; i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
            {
                n/=i;
            }
            c[++x]=i;
        }
    }
    if(n!=1)c[++x]=n;
    p=1;
    u=(long long)1<<61;
    while(p<=u)
    {
        m=(p+u)/2;
        y=m;
        for(int i=1; i<(1<<x); i++)
        {
            pr=1;
            for(int j=0; j<=x; j++)
            {
                if((i&(1<<j))>0)
                {
                    pr*=-c[j+1];
                }
            }
            y+=m/pr;
        }
        if(y<k)p=m+1;
        else u=m-1;
    }
    g<<p<<'\n';
    return 0;
}