Cod sursa(job #2640634)

Utilizator bianca.ialangiBiancaI bianca.ialangi Data 7 august 2020 02:58:34
Problema Factorial Scor 95
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <stdio.h>

int main() {
	long long int x, aux, x_max, p, s;

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

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

	if (p == 0)
		x = 1;
	else 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, "%lld\n", x);

	fclose(in);
	fclose(out);

	return 0;

}