Cod sursa(job #3141305)

Utilizator sireanu_vladSireanu Vlad sireanu_vlad Data 13 iulie 2023 14:56:40
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.48 kb
#include <iostream>

using namespace std;

typedef unsigned long long ull;

ull fact5(ull x)
{
	int k = 0;
	while(x)
		k += x/5, x /= 5;
	return k;
}

int main()
{
	freopen("fact.in", "r", stdin);
	freopen("fact.out", "w", stdout);

	ull p; cin >> p;
	
	ull index = 0;
	for(int bit = 63; bit >= 0; bit--)
	{
		index += ull(1<<bit);
		if(fact5(index) >= p) index -= ull(1<<bit);
	}
	index++;

	if(p == fact5(index)) cout << index;
	else cout << -1;

	return 0;
}