Cod sursa(job #354731)

Utilizator nightwish0031Vlad Radu Cristian nightwish0031 Data 9 octombrie 2009 12:04:02
Problema Factorial Scor 100
Compilator cpp Status done
Runda cautb1 Marime 0.41 kb
#include<stdio.h>

int nzero(int n)
{
	int r=0;
	
	while (n)
		r+=(n/=5);
	
	return r;
}


int cb(int p)
{
	int i,pas=(1<<30);
	--p;
	for (i=0 ; pas ; pas>>=1)
		if (nzero(i+pas)<=p)
			i += pas;
	if (nzero(i+1)!=(p+1)) return -1;
	return i+1;
}

int main()
{int p;
	
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	
	scanf("%d",&p);
	
	printf("%d",cb(p));
	return 0;
}