Cod sursa(job #1518588)

Utilizator George-AndreiGeorge Andrei George-Andrei Data 5 noiembrie 2015 23:45:42
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.37 kb
#include<stdio.h>

int main() {
	int p, n = 0, copy;
	freopen("fact.in", "r", stdin);
	freopen("fact.out", "w", stdout);
	scanf("%d", &p);
	if (p == 0) {
		printf("%d", 1);
		return 0;
	}
	while (p > 0) {
		n += 5;
		copy = n;
		while (copy) {
			if (copy % 5 == 0)--p;
			copy /= 5;
		}
	}
	if (p == 0)printf("%d", n);
	else printf("%d", -1);
	return 0;
}