Pagini recente » Cod sursa (job #819709) | Cod sursa (job #2455826) | Cod sursa (job #1053780) | Cod sursa (job #2387894) | Cod sursa (job #950303)
Cod sursa(job #950303)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
long get_count(int P) {
long count=0, i, tmp;
i=0;
while (i<P && count<P) {
i++;
count++;
tmp = i;
//printf("i=%ld count=%ld tmp = %ld\n", i, count, tmp);
while(tmp>0 && tmp%5==0) {
count++;
tmp = tmp / 5;
}
}
if(count>P)
return -1;
return i*5;
}
int main(int argc, char *argv[]) {
long P, N;
clock_t start = clock();
FILE *f1 = fopen("fact.in", "r");
fscanf(f1, "%ld", &P);
fclose(f1);
f1 = fopen("fact.out", "w");
N = get_count(P);
fprintf(f1, "%ld\n", P>0?N:1);
fclose(f1);
printf ( "%f ms\nN = %ld\n", ( (double)clock() - start ) * 1000 / CLOCKS_PER_SEC , N);
return 0;
}