Cod sursa(job #588156)

Utilizator balakraz94abcd efgh balakraz94 Data 7 mai 2011 09:21:07
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<cstdio>
using namespace std;

int p,n;
void citeste();
void rezolva();
void afiseaza(int);
int legendre(int);

void citeste()
{
	freopen("fact.in","r",stdin);
	
	scanf("%d",&p);
	
	fclose(stdin);
}



int legendre(int n)
{
	int paux=5,s=0;
	
	while(n/paux)
	{
		s+=n/paux;
		paux*=5;
	}
	
	return s;
}

void rezolva()
{
	
	int rez=0;
	n=0;
	
	while(rez<p)
	{
		n+=5;
		rez=legendre(n);
	}
	if(rez==p) afiseaza(n);
	else afiseaza(-1);
}


void afiseaza(int sol)
{
	freopen("fact.out","w",stdout);
	
	printf("%d\n",sol);
	
	fclose(stdout);
}

int main()
{
	citeste();
	rezolva();
}