Cod sursa(job #475706)

Utilizator Cosmin1490Balan Radu Cosmin Cosmin1490 Data 8 august 2010 02:01:03
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
#define NMAX 5900000

using namespace std;
unsigned char A[NMAX];
int P;

fstream fout("fact.out",ios::out);
void preproc()
{
	for(int j=1;j<NMAX/5;j*=5)
		for(int i=j;i<NMAX;i+=j)
		{
			A[i]++;
		}
	
}

void proc(int x)
{
	
	
	int S=0;
	int i=0;
	while(x>S)
	{
		S=S+A[++i];
	}
	if(x!=0)
		if(x==S)
			fout<<i*5;
		else fout<<"-1";
	else fout<<"1";
	fout<<"\n";
}

int main(int argc,char *agv[])
{
	fstream fin("fact.in",ios::in);
	preproc();
	fin>>P;
	proc(P);
//	for(int i=100000000;i>=1;i--)
//		proc(i);
	fin.close();
}