Cod sursa(job #1714033)

Utilizator dragostanTantaru Dragos Constantin dragostan Data 7 iunie 2016 10:16:52
Problema GFact Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
int pas=1<<30,p,q;
int fact[1000000000];
int putere(int,int);
long long nr(int,int,int);
int main()
{
    int i=0,cop,m,aaa;
    long long j,fmax=-1;
    register int d=2;
    in >> p >> q;
    cop=p;
    for(; d*d<=cop; ++d)
        while(cop%d==0)
        {
            cop/=d;
            fact[d]+=q;
            m=d;
        }
    if(cop>1)
    {
        fact[cop]+=q;
        m=cop;
    }
    for(i=2; i<=m; ++i)
    {
        if(fact[i])
        {
            j=0;
            while(pas)
            {

                if(nr(j+pas,i,fact[i])<=p)
                    j+=pas;
                pas/=2;
            }
        }
        if(j>fmax)
        {
            fmax=j;
            aaa=i;
        }
    }
    while(nr(fmax,aaa,fact[aaa])==p)
    {
        --fmax;
    }
    out << ++fmax;
    cout << nr(fmax,aaa,fact[aaa]) << ' ' << fmax << ' ' << aaa << ' ' << fact[aaa] << "\n";
    return 0;
}
long long  nr(int n,int nr,int put)
{
    int copie;
    long long div=0;
    while(put)
    {
        copie=n;
        while(copie>=nr)
        {
            div+=copie/nr;
            copie/=nr;
        }
        --put;
    }
    return div;
}