Cod sursa(job #800954)
Utilizator | Dragos Martac Master011 | Data | 22 octombrie 2012 22:40:05 |
---|---|---|---|
Problema | Factorial | Scor | 25 |
Compilator | c | Status | done |
Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <stdio.h>
int zero(int x){
int r=0;
while(x>=5){
r+=x/5;
x/=5;
}
return r;
}
int caut(long long int p){
int i=0,pas=1<<21;
while(pas!=0){
if(zero(i+pas)<p)
i+=pas;
pas/=2;
}
return 1+i;
}
int main(){
FILE *fin,*fout;
fin=fopen("fact.in","r");
fout=fopen("fact.out","w");
long long int p,rez;
fscanf(fin,"%I64d",&p);
rez=caut(p);
if(zero(rez)!=p)
rez=-1;
fprintf(fout,"%I64d",rez);
fclose(fin);
fclose(fout);
return 0;
}