Cod sursa(job #2402445)

Utilizator VadimCCurca Vadim VadimC Data 10 aprilie 2019 18:24:31
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n, p;

int zero(int n){
	int z = 0, f = 5;
	while(n >= f){
		z += n / f;
		f *= 5;
	}
	return z;
}

int main(){
	int st = 0;
	int dr = 500000000;
	int m;
	int i, sol = -1, z;
	
	fin >> p;
	while(st <= dr){
		m = (st + dr) / 2;
//		cout << m << ' ';
		z = zero(m);
		if(z < p) st = m + 1;
		else if(z > p) dr = m - 1;
		else{
			sol = m;
			dr = m - 1;
		}
	}
	
	fout << sol;
}