Cod sursa(job #2636632)

Utilizator invoIlioi Alexandru invo Data 18 iulie 2020 23:33:08
Problema Factorial Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include<fstream>
#include<iostream>
using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");

int numOf5(int a)
{
	int b = 0;
	while (a % 5 == 0 && a != 0)
	{
		b++;
		a /= 5;
	}
	return b;
}

int main()
{
	int n,p = 0, s = 25;
	f >> n;
	if (n == 0)
	{
		g << 1;
		return 0;
	}
	while (p < n)
	{
		p += numOf5(s / 5) + 5;
		s += 25;
	}
	s -= 25;
	while (p > n)
	{
		p -= numOf5(s / 5) + 1;
		s -= 5;
	}
	if (p == n)
		g << s;
	else
		g << -1;
	return 0;
}