Cod sursa(job #1833022)

Utilizator zazavatar12Marton Alexandru-Sergiu zazavatar12 Data 21 decembrie 2016 14:23:56
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
// Week 2 - prob 3.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
	int n, nr_de_zero, s=0, putere=5;
	//cin >> nr_de_zero;
	f>>nr_de_zero;
	if (nr_de_zero == 0) g<<1; //cout << 1;
	else
	{
		for (n = 5; ; n+=5)
		{
			putere = 5;
			s = 0;
			while (putere <= n)
			{
				s += n / putere;
				putere *= 5;
			}
			if (s == nr_de_zero)
			{
				break;
			}
			else if (s > nr_de_zero)
			{
				break;
			}
		}

		if (s == nr_de_zero)
		{
			//cout << n << '\n';
			g<<n<<'\n';
		}
		else g<< "-1\n"; //cout << "-1\n";

	}

    return 0;
}