Pagini recente » Cod sursa (job #369686) | Cod sursa (job #470434) | Cod sursa (job #1536599) | Cod sursa (job #3200296) | Cod sursa (job #988426)
Cod sursa(job #988426)
#include<stdio.h>
int P, N, k, q = 5;
int power(int x){
if(x >= N)
return 0;
else{
q = q * 5;
return 1 + power(x * 5);
}
}
int count(int q){
if(q * 4 <= N)
return 4;
else
if(q * 3 <= N)
return 3;
else
if(q * 2 <= N)
return 2;
}
int main(){
FILE *pf, *pg;
pf = fopen("fact.in", "r");
pg = fopen("fact.out", "w");
fscanf(pf, "%d", &P);
N = P * 5;
if(P == 0)
N = 1;
else
if(N > 5){
k = power(5);
N = N - 5 * count(q) * (k - 1) * k / 2;
}
fprintf(pg, "%d", N);
fclose(pf);
fclose(pg);
return 0;
}