Cod sursa(job #503551)

Utilizator PetcuIoanPetcu Ioan Vlad PetcuIoan Data 23 noiembrie 2010 17:24:37
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include<stdio.h>
int x,ter;

int leg (int a)
{
	int s=0,p=5;
	while(a/p)
		{s=s+a/p;p=p*5;}
	return s;
}
int ctbn(int x)
{
	int st,dr,med,last,rem;
	st=1;
	dr=x;
	while(dr>=st)
	{
		med=st+((dr-st)>>1);
		rem=leg(med*5);
		if(rem==x)
		  return med*5;
		if(rem<x)
			st=med+1;
		if(rem>x)
			dr=med-1;
	}
	return -1;
}
int main()
{
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%d",&x);
	if(x==0)
	{printf("1");return 0;}
	else
		ter=ctbn(x);
	printf("%d",ter);
	return 0;
}