Cod sursa(job #687125)

Utilizator sk8ervinMaftei Ervin sk8ervin Data 22 februarie 2012 09:22:23
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include<fstream>
using namespace std;
int main()
{ 
	ifstream f("fact.in");
    ofstream g("fact.out");
	long p,ok=0,n,twos=0,fives=0,pp;
	f>>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) g<<-1;
	else g<<ok;
	f.close();
	g.close();
	return 0;
}