Pagini recente » Cod sursa (job #1744713) | Cod sursa (job #2457680) | Cod sursa (job #1241503) | Cod sursa (job #1706917) | Cod sursa (job #950253)
Cod sursa(job #950253)
#include <stdio.h>
double fact(int N) {
if(N==0 || N==1)
return 1;
int i;
long sol = 1;
for(i=2; i<=N; i++)
sol *= i;
return sol;
}
long get_count(int P) {
long count=0, i, N, tmp;
N = 5*P;
i=5;
while (i<N && count<P) {
count++;
tmp = i/5;
printf("i=%ld count=%ld tmp = %ld\n", i, count, tmp);
while(tmp%5==0 && tmp>0) {
count++;
tmp = tmp / 5;
}
if(count<P)
i+= 5;
}
if(count>P)
return -1;
return i;
}
int main(int argc, char *argv[]) {
long P, N, h;
printf("argc = %d argv[0] = %s\n", argc, argv[0]);
if(argc==2) {
N = atoi(argv[1]);
printf("%ld ! = %f\n", N, fact(N));
}
FILE *f1 = fopen("fact.in", "r");
fscanf(f1, "%ld", &P);
fclose(f1);
f1 = fopen("fact.out", "w");
N = get_count(P);
/*
N = 5*P;
if(N<25) {
fprintf(f1, "%d\n", P>0?N:1);
} else if(N<125) {
fprintf(f1, "%d\n", N-5);
} else if(N<625) {
h = N/25;
fprintf(f1, "%d\n", );
}
*/
fprintf(f1, "%ld\n", P>0?N:1);
fclose(f1);
return 0;
}