Cod sursa(job #600909)

Utilizator luckyme91wiz kid luckyme91 Data 4 iulie 2011 03:12:01
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>

using namespace std;

int main () {

ifstream in ("fact.in");
ofstream out ("fact.out");

int n, i, count ,temp;

in >> n;
count = 0;
/*
for (i = 1;count < n; i++)
{
	if (i % 5 != 0)
		count++;
	else
	{
		temp = i;
		while (temp % 5 == 0)
		{
			count ++;
			temp /= 5;
		}
		count ++;
	}
	
	if (count == n)
	{
		out << i * 5;
		break;
	}

}*/
i = n * 5;
int pivot = 25;
int fives = 5;
count = 1;
if (25 == i)
	out << -1;
else

while (count * pivot <= i)
{
	i -= fives;
	count ++;
	if (count == 5)
	{
		pivot *= 5;
		count = 1;
		fives +=5;
	}
}
/*
if (n == 0)
	out << 1;
else
	if (count > n)
		out << -1;*/
if (n == 0)
	out << -1;
else
	out << i;
return 0;
}