Cod sursa(job #1834877)

Utilizator zazavatar12Marton Alexandru-Sergiu zazavatar12 Data 25 decembrie 2016 19:41:44
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;

int i, n, nr_de_zero, aux, s = 0, putere = 5;
long long getTrailingZeros(int n);


int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
	//int n, nr_de_zero, s=0, putere=5;
	f >> nr_de_zero;
	if (nr_de_zero == 0) g << 1;
	else
	{


		if (getTrailingZeros(nr_de_zero) == nr_de_zero)
		{
			g << i*5 << '\n';
		}
		else g << "-1\n";

	}

    return 0;
}

long long getTrailingZeros(int n)
{

	for ( i = 1; s < nr_de_zero; i++)
	{
		if (!(i % 5))
		{
			aux = i;
			while (aux % 5 == 0)
			{
				s++;
				aux /= 5;
			}

		}
		s++;

	}
	i--;
	return s;
}