Cod sursa(job #825202)

Utilizator RotaruSabinaRotaru Sabina RotaruSabina Data 27 noiembrie 2012 20:39:15
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include<fstream>
using namespace std;
int main ()
{
	ifstream f("fact.in");
	ofstream g("fact.out");
	int N,P,fact,k,ok,j;
	f>>P;
	ok=1;
	for(N=1;N<=INT_MAX&&ok;N++)
	{
		fact=1;
		for(j=1;j<=N;j++)
			fact*=j;
		k=0;
		while(fact&&k<=P)
		{
			if(fact%10==0){
				           k++;
						   fact/=10;
						  }
			else break;
		}
		if(P==k) {
			       g<<N;
				   ok=0;
		          }
	}
	  if(ok) g<<-1;
	f.close();
	g.close();
}