Cod sursa(job #84007)

Utilizator mordredSimionescu Andrei mordred Data 12 septembrie 2007 23:43:34
Problema Factorial Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<cstdlib>
#include<string>

long long pow5(int x);

const long long MAXSIZE=20000001;
char fiveFlags[MAXSIZE];
long long n;
long long aux,add,t;
long long i,x;
int int_i;

int main(){

freopen("fact.in","r",stdin);freopen("fact.out","w",stdout);
scanf("%lld",&n);

t=5;int_i=1;
while(t<=MAXSIZE)
    {
     while(t*x<=MAXSIZE)   
        {
         fiveFlags[t*x]=int_i;
         x++;   
        }
     int_i++;t*=5;x=1;   
    }
    
i=1;add=0;
while(i+add<n)
    {
     i++;add+=fiveFlags[i];
    }
    
printf("%lld\n",(i+add==n)?i*5:-1);
        
return 0;    
}