Cod sursa(job #805397)

Utilizator sorincusmareIacob Sorin sorincusmare Data 31 octombrie 2012 13:09:34
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include<stdio.h>
using namespace std;
int zero(int n)
{
	int nr=0;
	while(n>=5)
	{
		nr+=n/5;
		n=n/5;
	}
	return nr;
}
int bs(int x)
{
	int i=0,pas=1<<30;
	while(pas!=0)
	{
		if(zero(i+pas)<x)
			i=i+pas;
		pas=pas/2;
	}
	return i+1;
}
int main()
{
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	int p,n;
	scanf("%d",&p);
	n=bs(p);
	if(zero(n)==p)
		printf("%d\n",n);
	else
		printf("-1");
	return 0;
}