Cod sursa(job #2072086)

Utilizator eilerGabriel-Ciprian Stanciu eiler Data 21 noiembrie 2017 13:02:29
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>
using namespace std;

int P;

int nrCifreZero(int x){
  int rez, pow;

  rez=0; pow=5;
  while (pow<=x){
    rez+=x/pow;
    pow*=5;
  }
  return rez;
}

int main(){
	int i, j, m;

	ifstream fin ("fact.in");
	fin >> P;
	fin.close();

	i=1; j=5*P;
	while (i<=j){
		m=(i+j)/2;
		if (nrCifreZero(m)>=P)
			j=m-1;
		else
			i=m+1;
	}

	ofstream fout ("fact.out");
	if (P<0)
		fout << "-1\n";
	else if (P==0)
		fout << "1\n";
	else
		fout << j+1 << '\n';
	fout.close();

	return 0;
}