Cod sursa(job #562232)

Utilizator nicknameLare Nicu nickname Data 22 martie 2011 17:41:48
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>
#include <iostream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int NrZero(int x){
	int z=0;
	for (long long i=5; i<=x; i*=5)
		z+=x/i;
	return z;
}

int BS(int p){
	int l=0, r=p*10, m,z;
	if (p==0)
		return 1;
	while (l<=r){
		m=(l+r)/2;
		z=NrZero(m);
		if (z==p){
			while (m%5 != 0)
				m--;
			return m;
		}
		else 
			if (z>p)
				r=m-1;
			else
				l=m+1;
	}
	return -1;
}

int main(){
	int p;
	fin>>p;
	fout<<BS(p);
	fin.close();
	fout.close();
	return 0;
}