Cod sursa(job #438124)

Utilizator vladstoickvladstoick vladstoick Data 10 aprilie 2010 15:06:00
Problema GFact Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include<stdio.h>
long i , j , x , n , p , q , pi [10001] , pp[10001]  ;
void div()
{
	int putere;
	for(i=2;i*i<=p;i++)
	{
		putere=0;
		while(p%i==0)
		{
			putere++;
			p/=i;
		}
		if(putere==0)
			continue;
		pi[++j]=i;
		pp[j]=putere*q;
	}
	if(p!=1)
	{
		pi[++j]=p;
		pp[j]=q;
	}

}
int put(int x,int y)
{
	int xy=0;
	while(x)
	{
		xy+=x/y;
		x/=y;
	}
	return xy;
}
bool verif(int n)
{
	for(i=1;i<=j;i++)
		if(put(n,pi[j])<pp[i])
			return 0;
	return 1;
}

int caut()
{
	long long x;
	long long pas=1<<60;
	for(x=0;pas;pas>>=1)
	{
		if(!verif(x+pas))
			x+=pas;
	}
	return x;
}
int main()
{
	freopen("gfact.in","r",stdin);
	freopen("gfact.out","w",stdout);
	scanf("%ld%ld",&p,&q);
	div();
	p=1;
	printf("%d",caut()+1);
	return 0;
}