Cod sursa(job #798575)
| Utilizator | Data | 16 octombrie 2012 19:29:18 | |
|---|---|---|---|
| Problema | Factorial | Scor | 25 |
| Compilator | c | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <stdio.h>
int zero(int x){
int r=0;
while(x>=5){
r+=x/5;
x/=5;
}
return r;
}
int caut(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");
int p,rez;
fscanf(fin,"%d",&p);
rez=caut(p);
if(zero(rez)!=p)
rez=-1;
fprintf(fout,"%d",rez);
fclose(fin);
fclose(fout);
return 0;
}
