Cod sursa(job #805386)

Utilizator sorincusmareIacob Sorin sorincusmare Data 31 octombrie 2012 12:49:49
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include<stdio.h>

int zero(int n){
    int nr=0 ;
    while(n>=5){
        nr+=(n/5);
        n/=5;
    }
return nr;
}

int caut(int x){
    int i=0,pas;
    pas=1<<29;
while (pas!=0)
{ if (zero(i+pas)<x)
     i +=pas;
     pas /= 2;
}
return i+1;
}

int main(){
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int p,r;
scanf("%d",&p);
r=caut(0);
 if(zero(r)==p)
 printf("%d\n",r);
  else
 printf("-1") ;
 return 0;
 }