Cod sursa(job #429268)

Utilizator tudgal1001Profir Tudor tudgal1001 Data 29 martie 2010 23:41:52
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include<stdio.h>
#include<values.h>
using namespace std;

int nr_zero (int k)
{
	int sum=0;
	int putere=5;
	while (k%putere>0)
	{
		sum+=k/putere;
		putere*=5;
	}
	return sum;
}

int main ()
{
	int st,dr,p,m;
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%d",&p);
	st=1; dr=5*p;
	while (st<=dr)
	{
		m=st+(dr-st)/2;
		if (nr_zero(m)>=p)
			dr=m-1;
		else st=m+1;
	}
	if (p==0) printf("1");
	else if (nr_zero(m)==p) printf("%d",m);
	else printf("-1");
	return 0;
}