Cod sursa(job #843836)

Utilizator gerd13David Gergely gerd13 Data 28 decembrie 2012 15:21:56
Problema Factorial Scor 0
Compilator cpp Status done
Runda 23dezile_2 Marime 0.42 kb
#include<iostream.h>
#include<fstream.h>

ifstream in("fact.in");
ofstream out("fact.out");

int main()
{
	int p,ok=0,n,twos=0,fives=0,pp;
	in>>p;

	for(n=1;ok==0 && n>0;n++)
	{
		pp=n;
		while(pp%5==0 || pp%2==0){
			if (pp%2==0) { twos++; pp=pp/2;}
			if (pp%5==0) { fives++; pp=pp/5;}
			}

		if(twos>=p && fives>=p) ok=n;
	}

	if(ok==0) out<<-1;
	else out<<ok;

	out.close();
	in.close();

	return 0;
}