Cod sursa(job #218635)

Utilizator SliMMStefan Saftescu SliMM Data 2 noiembrie 2008 20:28:35
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
/*
 * factorial.cpp
 *
 *  Created on: Nov 2, 2008
 *      Author: stefan
 */

#include<stdio.h>

int main()
{
	long int P, N, i;

	freopen("fact.in", "r", stdin);
	freopen("fact.out", "w", stdout);

	scanf("%ld", &P);

	if (P == 0)
	{
		printf("1");
		return 0;
	}

	for (N = 5; P > 0; N += 5)
	{
		i = N;
		while (i % 5 == 0)
		{
			--P;
			i /= 5;
		}
	}

	if (P)
		printf("-1");
	else
		printf("%ld", N-5);
	return 0;
}