Cod sursa(job #549985)

Utilizator GaborGabrielFMI - GabrielG GaborGabriel Data 9 martie 2011 09:35:16
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream.h>
#include <math.h>
ifstream f("fact.in");
ofstream g("fact.out");
long long p,i,l,S,max,m,aux,k;


int functie(long long n)
{
	S=0;
	l=log(n)/log(5);
	//g<<l<<'\n';
	for(k=1;k<=l;k++)
		S=S+n/(pow(5,k));
	return S;
}


void cautbinar(long long st,long long dr)
{
	m=(st+dr)/2;
	aux=functie(m);
	if(aux==p)
		g<<m;
	else		
		if(aux<p)
			cautbinar(m,dr);
		else
			cautbinar(st,m);
}

int main()
{
	f>>p;
	max=5*p;
	cautbinar(0,max);
	f.close();
	g.close();
	return 0;
}