Cod sursa(job #1106525)

Utilizator stefan.friptuPetru Stefan Friptu stefan.friptu Data 12 februarie 2014 21:24:32
Problema GFact Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<stdio.h>
#include<math.h>
 
int v[20],put[20];
 
int main()
{
    freopen("gfact.in","r",stdin);
    freopen("gfact.out","w",stdout);
    int p,q,i,j=0,nr=0,max=0;
    int b,exp;
    scanf("%d%d",&p,&q);
    p=pow(p,q);
 
    for(i=2;i<=p;i++)
    {
        j=0;
        while(p%i==0)
        {
            p=p/i;
            j++;
        }
        if(j>0)
        {
            v[++nr]=i;
            put[nr]=j;
        }
    }
 
    for(i=1;i<=nr;i++)
    {
        exp=1;
        b=v[i];
        while(exp<put[i])
        {
            b+=v[i];
            exp+=b/v[i];
        }
        if(b>max)
            max=b;
    }
 
    printf("%d\n",max);
    return 0;
}