Cod sursa(job #588490)

Utilizator eu295Opris Dragos eu295 Data 8 mai 2011 12:24:42
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 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;
	while (ok==false)
	{
		if (p==0)
		{
			fout<<"1"<<endl;
			ok=true;
		}
		else
		{
			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;
}