Cod sursa(job #433575)

Utilizator O_NealS. Alex O_Neal Data 3 aprilie 2010 21:22:30
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<cstdio>
#include<fstream>
using namespace std;

int p;

int bun(int x)
{
	int cont=0;
	int putere=5;
	while(x>=putere)
	{
		cont+=(x/putere);
		putere*=5;
	}
	if (cont>=p) return 1;
	return 0;
}


int main()
{
	ifstream fin("fact.in");
	//freopen("fact.out","w",stdout);
	ofstream fout("fact.out");
	fin>>p;
	
	unsigned long long s=0,d=4200000000,m;
	unsigned long long rez=0;
	if(p==0) { fout<<1; return 0; }
	else
	while(s<=d)
	{
		m=(s+d)>>1;
		if(bun(m)) 
			{
				rez=m;
				d=m-1;
			}
		else s=m+1;
	}
	
	//printf("%lld\n",rez);
	if(rez) fout<<rez;
	else fout<<-1;
	return 0;
}