Pagini recente » Rating Florea Vasile Alexandru (TheAlex1) | Monitorul de evaluare | Profil ash262 | Statistici vasile (eto5072) | Cod sursa (job #2834329)
#include <stdio.h>
int main() {
char *inFileName = "fact.in";
char *outFileName = "fact.out";
FILE *in = fopen(inFileName, "r");
if (in == NULL) {
printf("Cannot open %s.\n", inFileName);
return 1;
}
FILE *out = fopen(outFileName, "w");
int p;
fscanf(in, "%d", &p);
if (p == 0) {
fprintf(out, "%d", 1);
} else {
int count = 0;
int current;
int powers[12] = {0};
for (current = 1; count < p; current++) {
count++;
powers[0]++;
for (int i = 0; i < 11; ++i) {
if (powers[i] % 5 == 0) {
powers[i + 1]++;
count++;
} else {
break;
}
}
}
if (count == p) {
fprintf(out, "%d", (current - 1) * 5);
} else {
fprintf(out, "%d", -1);
}
}
fclose(in);
fclose(out);
return 0;
}