Cod sursa(job #3206243)

Utilizator CzarPopescu Cezar Stefan Cristian Czar Data 22 februarie 2024 01:21:07
Problema Factorial Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb

#include <iostream>
#include <limits.h>
#include <queue>
#include <string>
#include <map>
#include<vector>
#include <set>
#include<stack>
#include <queue>
#include<algorithm>
#include <fstream>
#include <iomanip>
#include<cmath>
#include<iostream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");

int getNumberOfFives(int x) {
	int l = 5, ans=0;
	while (l <= x) {
		ans += x / l;
		l *= 5;
	}
	return ans;
}
int main()
{
	int p;
	in >> p;
	int st = 1, dr=2e8;
	if (p == 0) {
		out << 1;
		return 0;
	}
	while (st < dr) {
		int mijl = (dr + st) / 2;
		if (getNumberOfFives(mijl) < p) {
			st = mijl + 1;
		}
		else {
			dr = mijl;
		}
	}
	if (getNumberOfFives(st) >= p)out << st;
	else out << -1;
	
	return 0;
}