Cod sursa(job #801934)

Utilizator Alexandru098Costea Vlad Alexandru098 Data 25 octombrie 2012 14:35:09
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<stdio.h>

int n,min,max,p,last,x;

int ok(int x)
{
	int i=1,l=1,s=0;
	while(l<x)
	{
		l*=5;
		s+=x/l;
		i++;
	}
	if(s>=p)
	{
		return 1;
	}
	return 0;
}

int main()
{
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%d",&p);
	if(p==0)
	{
		printf("1");
		return 0;
	}
	max=p*5;
	min=1;
	while(min<=max)
	{
		x=(min+max)/2;
		if(ok(x))
		{
			last=x;
			max=x-1;
		}
		else
		{
			min=x+1;
		}
	}
	if(last!=0)
	{
		printf("%d",last);
	}
	else
	{
		printf("-1");
	}
	return 0;
}