Cod sursa(job #1047802)

Utilizator RaduStefanFMI - Radu Stefan RaduStefan Data 4 decembrie 2013 21:34:37
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include<fstream>
#include<math.h>
using namespace std;
long long sol=-1,p;
int verif(long long a)
{
	unsigned i=0,s=0;
	long long b=5;
	while(b<=a)
	{
		i++;
		b=pow(5,i);
		s+=a/b;
		if(s>=p)return 1;
	}
	return 0;
}
void bin2()
{
	long long poz=0;
	long long pas=(1<<7);
	while(pas>0)
	{
			if( verif(poz+pas)==1)sol=poz+pas;
				else poz+=pas;
		pas>>=1;
	}
}
int main()
{
	ifstream fcin("fact.in");
	ofstream fcout("fact.out");
	fcin>>p;
	if(p==0)fcout<<1;
	else 
	{
	bin2();
	if(sol%5!=0)fcout<<-1;
	else fcout<<sol;
	}
	return 0;
}