Cod sursa(job #2640558)

Utilizator bianca.ialangiBiancaI bianca.ialangi Data 6 august 2020 20:25:14
Problema Factorial Scor 90
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <stdio.h>

int main() {
	int p, s;

	long x, aux, x_max;

	FILE *in = fopen("fact.in", "rt");
	FILE *out = fopen("fact.out", "wt");
	
	fscanf(in, "%d", &p);

	x = 4 * p;
	x_max = 5 * p + 1;
	aux = x;

	if (p == 0)
		x = 1;
	else {
		while (x < x_max) {
			s = 0;
			while (aux) {
				s += aux/5;
				aux /= 5;
			}
			if (s == p){
				break;
			} else if (s < p) {
				x++;
				aux = x;
			} 
		}
	}

	if (s != p)
		x = -1;

	fprintf(out, "%ld\n", x);

	fclose(in);
	fclose(out);

	return 0;

}