Cod sursa(job #726789)

Utilizator Dragan_ValentinDragan Valentin Dragan_Valentin Data 27 martie 2012 15:27:03
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
#include <iostream>
#include <cmath>

using namespace std;

int p;


int nr_zero(int x)
{
	int i;
	long long nr=0;
	for (i=1; i<=10000; i++)
		if (x/(int)pow((double)5,i)==0) break;
		else nr+=x/(int)pow((double)5,i);
	return nr;
}


int main()
{
	ifstream f("fact.in");
	f>>p;
	f.close();
	int l=1,r=p*5,x;
	ofstream g("fact.out");
	while (l<=r) {
		x=nr_zero((l+r)/2);
		if (x==p) { g<<(l+r)/2-(l+r)/2%5; return 0; } 
		else if (x<p) l=(l+r)/2+1;
		else r=(l+r)/2-1;
	}
	if (p==0) g<<0;
	else g<<-1;
	g.close();
	return 0;
}