Cod sursa(job #2846908)

Utilizator PrelipceanRazvanPrelipcean Razvan Mihai PrelipceanRazvan Data 9 februarie 2022 20:17:26
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>

using namespace std;

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

	int n, x = 0, prev = 0, sum = 0, step;
	in >> n;
	if(n == 0)
	{
		out << 1;
		return 0;
	}

	while(x <= n)
	{
		prev = x;
		x = (x+1)*5;
	}
	step = prev;
	x = prev;
	while(x != 0)
	{
		while(step <= n)
		{
			prev = step;
			sum += x/5;
			step += x+1;
	// out << prev << " " << sum << " " << x << endl;
		}
	// out << endl;

		
		x = (x/5)-1;
		step = prev+x+1;
	}
	// out << prev << " " << sum << endl;
	if(prev == n)
		out << -1;
	else
		out << (n-sum)*5;
}