Cod sursa(job #806473)

Utilizator DaicuDaicu Alexandru Daicu Data 2 noiembrie 2012 21:46:39
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<stdio.h>
#include<math.h>
long long p;
int test(int n){
	int x,nr=0;
	for(int i=1;i<100;i++){
		x=(int)(n/pow(5,i));
		if(x)
			nr+=x;
		else{
			if(nr==p)
				return 1;
			if(nr<p)
				return -1;
			else 
				return 0;
		}
	}
}
void binsearch(){
	int f=1,l=100000,x;
		int midd;
		while(f<l){
			midd=(f+l)/2;
			x=test(midd);
				if(x==1 || x==0)
					l=midd;
				else
					f=midd+1;
		}
	if(test(l)==1)
		printf("%d",l);
	else
		printf("-1");
}
int main(){
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%lld",&p);
	if(!p)
		printf("1");
	else
		binsearch();
	
}