Cod sursa(job #629108)

Utilizator ContraPunctContrapunct ContraPunct Data 2 noiembrie 2011 17:30:01
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include<cstdio>
#include<fstream>
#include<vector>
#include <algorithm>
#define Nmax 804
using namespace std;
vector<int> bat; 
int n,p;
void ReadData()
{
	int i;
	ifstream fin("factorial.in");
	fin>>p;
	//sort(bat.begin(),bat.end());
}
int nr_zero(int a)
{
	int nr=0;
	while( a!=0 )
	{
		nr += a/5;
		a/=5;
	}
	return nr;
}
void Sol()
{
	ofstream fout("factorial.out");
	int stg,drp,m,nr0;
	stg = 1;
	drp = 5*p;
	while(stg<=drp)
	{
		m = (drp+stg)/2;
		nr0 = nr_zero(m);
		if( p > nr0 ) 
		{			
			stg = m+1;
		}
		else
			if(p == nr0)
			{
				if(m%5 == 0) 
					fout<<m<<"\n";
				else 
				{
					m=m-m%5;
					fout<<m<<"\n";
				}
				stg = drp+2;
			}
				else
				{
					drp = m-1;
				}	
	}
}
			
int main()
{	
	ReadData();
	if( p == 0 )
		printf("1\n");
	else
		Sol();
	return 0;
}