Cod sursa(job #671116)

Utilizator Andrei.XweCobzaru Adrian-Andrei Andrei.Xwe Data 30 ianuarie 2012 19:11:09
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.35 kb
using namespace std;
#include<fstream>
int main()
{
	long n,k,nr,P;
	ifstream fcin("fact.in");
	ofstream fcout("fact.out");
	fcin>>P;
	if(P<0)
		fcout<<-1;
	else
		if(P==0)
			fcout<<1;
		else{
	n=0;
	do{
		n+=5;
		nr=0;
		for(k=5;n/k>1;k*=5)
			nr+=n/k;
	}while(nr<P);}
	fcout<<n-5;
	fcin.close();
	fcout.close();
	return 0;
}