Pagini recente » Statistici Horotan Tudor (tudorhorotan) | Profil Ovid | Cod sursa (job #1534039) | Cod sursa (job #2673840) | Cod sursa (job #2756492)
#include <stdio.h>
#include <math.h>
const int range = 50;
int nrzerofact(int n){
int maxim = 0;
int copie = n;
while(copie) {
copie = copie/5;
maxim++;
}
int suma=0;
for(int i=1; i<maxim; i++){
suma+=n/pow(5,i);
}
return suma;
}
int main() {
FILE *in = fopen("fact.in", "r");
FILE *out = fopen("fact.out", "w");
int P;
fscanf(in, "%d", &P);
if(P==0){
fprintf(out, "%d", 1);
}else {
int k = P / 5 - range;
if (k < 0)k = 0;
while (nrzerofact((P - k) * 5) != P) {
k++;
}
fprintf(out, "%d", (P - k) * 5);
}
}