Cod sursa(job #588492)

Utilizator eu295Opris Dragos eu295 Data 8 mai 2011 12:29:37
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
	int b,a,p,N=5;bool ok=false;
	ifstream fin("fact.in");
	ofstream fout("fact.out");
	fin>>p;
	if (p==0)
	{
		fout<<"1"<<endl;
	}
	else
	{
		while (ok==false)
		{
			a=0;
			if (p>=a)
			{
				for (int i=0;i<=N;i=i+5)
				{
					b=i;
					while (b>=5)
					{
						if (b%5==0)
						{
							a++;
						}
						b=b/5;
					}
				}
				if (p==a)
				{
					fout<<N;
					ok=true;
				}
				N=N+5;
			}
			else
			{
				fout<<"-1"<<endl;
				ok=true;
			}
		}
	}
	
	return 0;
}