Cod sursa(job #444686)

Utilizator x.5p1k3Gheorghiu Andrei-Ionut x.5p1k3 Data 21 aprilie 2010 11:34:49
Problema Factorial Scor 100
Compilator cpp Status done
Runda Tema 10D #1 Marime 0.46 kb
#include <stdio.h>
#define MAX 1000000000
int n;
int bin(int p){int hi,mid,lo,e,a,max;
for (lo=1,hi=MAX+1,max=-1; lo<=hi; ){
mid=lo+(hi-lo)/2;
a=mid;
e=0;
while (a) { a = a/5; e+=a;}(a/=5);
if (e==p) max=mid;
if(p<=e) hi=mid-1;
else if(p>e) lo=mid+1;}
if (max!=-1)
return max;
return -1;}
int main()
{freopen ("fact.in","r",stdin);
freopen ("fact.out","w",stdout);
scanf ("%d",&n);
if (n==0) printf ("1");
else printf ("%d",bin(n));
return 0;}