Cod sursa(job #616288)

Utilizator dtoniucDaniel Toniuc dtoniuc Data 12 octombrie 2011 09:37:49
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <fstream>
using namespace std;
int p,n,s1;
int t[13]={0,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};
int x[13]={0,6,31,156,781,3906,19531,97656,488281,2441406,12207031,61035156,305175781};
int det(int nr)
{
	int z=0;
	for(int j=t[s1]+5;j<=nr;j+=5)
	{
		int aux=j;
		while(aux%5==0) 
		{
			aux/=5;
			z++;
		}
	}
	return z;
}
void caut(int s,int d)
{
	int m=(s+d)/2;
	int nr=det(m);
	if (s==d) n=m;
	else if(p>x[s1]+nr) caut(m+1,d);
		else caut(s,m);
}
int loc()
{
	int i=0;
	while (p>x[i]) 
		i++;
	return i;
}
int main()
{
	ifstream fin("fact.in");
	ofstream fout("fact.out");
	fin>>p;
	s1=loc()-1;
	caut(t[s1],t[s1+1]);
	fout<<n;
	return 0;
}