Cod sursa(job #491769)

Utilizator bocacristiBoca Nelu Cristian bocacristi Data 12 octombrie 2010 13:41:22
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <fstream>
using namespace std;

ifstream fin("factorial.in");
ofstream fout("factorial.out");

int f(int n);

int main()
{
		int p, n = 0, nrz = 0;
		int gata =0;
		fin >> p;
		
		while ( !gata )
		{
				n+= 5;
				nrz += f(n);
				if ( nrz >= p )
				gata = 1;
		}
		if ( nrz == p )
				fout << n;
		else
				fout << -1;
}

int f(int n)
{
		int x =0;
		while( n % 5 == 0 )
				x++, n/=5;
		
		return x;
}