Cod sursa(job #629107)

Utilizator ml.vladareanVladarean Maria ml.vladarean Data 2 noiembrie 2011 17:27:19
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>
using namespace std;
long long P;
long long suma(long long nr)
{
	long long s=0,x=nr,a=5;
	while (x!=0)
	{
		s+=nr/a;
		a*=5;
		x=x/5;
	}
	return s;

}


int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
long long M=0,st=1,dr;
fin>>P;
//n=4*P;
dr=5*P;
//M=st+(dr-st)/2;
//fout<<st<<" "<<dr<< " " <<P;



if(P==0)
	fout<<1;

else
{
	while (st <= dr && suma(M)!=P)
	{
		
		M=st+(dr-st)/2;
		
		if(suma(M)>=P)
			dr=M-1;
		else
			st=M+1;
	
	}
	//fout<<"M1 "<<M;
while(suma(M)>=P)
{
	M--;
}
fout<<M+1;
}

//fout<<suma(45);
	return 0;
}