Cod sursa(job #1711448)

Utilizator dragostanTantaru Dragos Constantin dragostan Data 31 mai 2016 11:45:12
Problema GFact Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
int pas=1<<30,p,q,maxdiv;
bool fact[1000000000];
int nr(int,int);
int putere
int main()
{
    int a,i=0,d=2,cop,m,fmax=-1;
    in >> p >> q;
    cop=p;
    for(d=2;d*d<=cop;++d)
        while(cop%d==0)
        {
            cop/=d;
            fact[d]++;
            m=d;
        }
    if(cop>1)
    {
        fact[cop]++;
        m=cop;
    }
    for(i=2;i<=m;++i)
    {
        int j=0;
        if(fact[i])
        while(pas)
        {
            if(nr(j+pas,fact[i])<=q)
                j+=pas;
            pas/=2;
        }
        if(j>fmax) fmax=j;
    }
    int aa=fmax;
    while(nr(fmax,fact[aa])==q)
    --fmax;
    out << ++fmax;
    return 0;
}
int nr(int n,int put)
{
    int div=0;
    while(n>=put)
    {
        div+=n/put;
        n/=put;
       // cout << n << " " << put << "\n";
    }
    return div;
}