Cod sursa(job #3206246)

Utilizator CzarPopescu Cezar Stefan Cristian Czar Data 22 februarie 2024 01:29:27
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 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=5e8;
	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-1;
		}
	}
	if (getNumberOfFives(st) == p)out << st;
	else out << -1;
	
	return 0;
}