Cod sursa(job #348310)

Utilizator hasegandaniHasegan Daniel hasegandani Data 15 septembrie 2009 11:05:21
Problema GFact Scor 20
Compilator cpp Status done
Runda Papiu Contest #1 Marime 0.63 kb
#include<stdio.h>

int p,q,s,i,j,k,l;
int mp,ni,max;
int rez;

int main()
{
    freopen("gfact.in","r",stdin);
    freopen("gfact.out","w",stdout);
    scanf("%d%d",&p,&q);
    
    for(i=2;i<=p;++i)
        {
        for(k=1 , l=0;p%i==0;p/=i , k*=i , ++l);
        if (max<k)
            {
            max=k;
            ni=i;
            mp=l;
            }
        }
        
    for(j=2 , s=1 ; s+j<=q ; s+=j , ++j);
    --j;
    
    i=max;
 //   printf("%d %d ",i,j);
    
    rez=1;
    for(int b=i;j;j/=2 , b*=i)
        if (j%2==1)
            rez*=b;
    
    printf("%d\n",rez);
    return 0;
}