Cod sursa(job #3319161)

Utilizator FistfullOfDollar059Andrei Marin Popa FistfullOfDollar059 Data 30 octombrie 2025 20:43:31
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;

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

	int p, ans = -1;
	fin>>p;

	long long a, b, k;
	a = 1;
	b = 10000000000;
	int last0;

	while(a <= b) {
		last0 = 0;
		k = (a+b)/2;
		while(k >= 5) {
			last0 += k/5;
			k /= 5;
		}
		k = (a+b)/2;
		if(last0 == p) {
			ans = k;
			b = k - 1;
		}else if(last0 < p) {
			a = k + 1;
		} else {
			b = k - 1;
		}
	}

	fout<<ans;

	return 0;
}