Cod sursa(job #629078)

Utilizator ml.vladareanVladarean Maria ml.vladarean Data 2 noiembrie 2011 17:05:26
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>
using namespace std;
int P;
int suma(int nr)
{
	int 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");
int M,st=1,dr;
fin>>P;
//n=4*P;
dr=10000000;
//M=st+(dr-st)/2;
//fout<<st<<" "<<dr<< " " <<P;



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

else
{
	while (st < dr)
	{
		M=(st+dr)/2;
	if(suma(M)>P)
		dr=M -1;
	else
		if(suma(M)<P)
		st=M+1;
		else
		{
			while(suma(M)==P)
			{
				M--;

			}
			fout<<M+1;
			break;
		}
	
	}
//fout<<"          "<<M;
}

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