Cod sursa(job #3141294)

Utilizator sireanu_vladSireanu Vlad sireanu_vlad Data 13 iulie 2023 14:38:55
Problema Factorial Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.37 kb
#include <iostream>
using namespace std;

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

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

	int p; cin >> p;
	int nr5 = 0, x = 0;

	while(nr5 < p)
	{
		x += 5;
		nr5 += fact5(x);
	}

	if(nr5 == p)
		cout << x;
	else cout << -1;

	return 0;
}