Cod sursa(job #731974)

Utilizator MutescuMutescu Alexandru Mutescu Data 9 aprilie 2012 14:54:43
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include<cstdio>
using namespace std;
long long a,b,l,k,g,i,o,t,u,p,x=2,m,y;


long long lol(long long  v){
	long long c=5,s=0;
	while(v/c>0){
		s=s+v/c;
		c=c*5;}
	
	return s;}


int main(){
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%lld",&p);
	y=100000000000000ll;
	if(p==0)
		printf("%d\n",1);
	else{
		while(x<=y && b!=1){
		 m=(x+y)/2;
		 u=lol(m);
		  if(u==p){
			  b=1;
			  k=m;}
		   	else
				if(u>p)
					y=m-1;
				else
					x=m+1;}
		if(b==0)
			printf("%d\n",-1);
		else
			printf("%lld\n",k-k%5);}
	return 0;}