Cod sursa(job #2329646)

Utilizator Mihai0290Ilie Mihai-Alexandru Mihai0290 Data 27 ianuarie 2019 11:04:40
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;
int P, N;
ifstream in("fact.in");
ofstream out("fact.out");
int GetTrailing0s(int n)
{
	int count = 0;
	for (int i = 5; (n/i) > 0; i = i * 5)
	{
		count = count + (n / i);
	}
	return count;
}
int main()
{
	in >> P;
	int m, st = 1, dr = 500000000;
	while (st < dr)
	{
		m = (st + dr) / 2;
		if (GetTrailing0s(m) < P)
			st = m + 1;
		else
			dr = m;
	}
	if (P == GetTrailing0s(st))
	{
		out << st;
	}
	else
	{
		out << -1;
	}
    return 0;
}