Pagini recente » Cod sursa (job #1580747) | Cod sursa (job #2133815) | Cod sursa (job #1276342) | Cod sursa (job #1620806) | Cod sursa (job #1218846)
#include <stdio.h>
FILE *f,*g;
int zero(int n){
int rasp=0;
/*while (n>=5) {
rasp+=n/5;
n/=5;
}*/
int x = 1;
while(x*5<=n){
x*=5;
rasp+=n/x;
}
return rasp;
}
int cautbin(int left, int right, int x){
if(left==right){
if(zero(right)==x)
return right;
else
return -1;
}
int mid=(left+right)/2;
if(zero(mid) >= x){
return cautbin(left,mid,x);
} else {
return cautbin(mid+1,right,x);
}
}
int main() {
int p;
f=fopen("fact.in","r");
g=fopen("fact.out","w");
fscanf(f,"%d",&p);
fprintf(g,"%d",cautbin(1,2000000000,p));
return 0;
}