Cod sursa(job #482303)

Utilizator borsoszalanBorsos Zalan borsoszalan Data 3 septembrie 2010 00:00:15
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <stdio.h>

int a[1000],p;

int nr(int k){
int temp,i=1;

temp=k/5;

while(a[i]<=k){temp+=k/a[i];i++;}

return temp;

}


int bs(int lo,int hi){
int mid;

while(lo<hi){
mid=lo+(hi-lo)/2;
if(nr(mid)>=p){hi=mid;}else{lo=mid+1;}

}

if(nr(lo)==p){return lo;}else{return -1;}

}

int main(){
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%d",&p);
	int i=1;
	if(p==0){printf("1");}else{
	a[i]=25;

	while(a[i]<=5*p){i++;a[i]=a[i-1]*5;}

	

	printf("%d",bs(0,5*p));
	}

	return 0;}