Cod sursa(job #2846894)

Utilizator PrelipceanRazvanPrelipcean Razvan Mihai PrelipceanRazvan Data 9 februarie 2022 19:50:44
Problema Factorial Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>

using namespace std;

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

	int n, x = 0, prev, sum = 0, step;
	in >> n;

	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;
		}

		step = prev;
		x = (x/5)-1;
	}

	if(prev == n)
		out << -1;
	else
		out << (n-sum)*5;

	// int sum = 0, aux = 0, k = 0;
	// for(int i = 1; i <= n; i++)
	// {
	// 	k++;
	// 	out << i << " : " << k << "		" << i-k << endl;
	// 	if(!(k%5))
	// 	{
	// 		aux = k;
	// 		while(aux&&(!(aux%5)))
	// 		{
	// 			out << ++i << " : " << k << "		" << i-k << endl;
	// 			aux /= 5;
	// 		}
	// 	}
		
	// }
}