Cod sursa(job #2609794)

Utilizator smitoiStefan Mitoi smitoi Data 3 mai 2020 16:04:50
Problema Factorial Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <algorithm>
// #include <chrono>

using	namespace std;

// Reference: http://www.cplusplus.com/reference/algorithm/nth_element/


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

long int		p, v[2];
long long int	nr;

int	impCinci()
{
	long long int aux = nr;
	long long int k = 0;
	while (aux % 5 == 0)
	{
		aux /= 5;
		k++;
	}
	return k;
}

int	impDoi()
{
	long long int aux = nr;
	long long int k = 0;
	while (aux % 2 == 0)
	{
		aux /= 2;
		k++;
	}
	return k;
}

int	main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	
	v[0] = 0;
	v[1] = 0;
	
	f >> p;
	
	for (nr = 2; v[0] < p || v[1] < p; nr++)
	{
		v[0] += impCinci();
		v[1] += impDoi();
	}

	if (v[0] > p && v[1] > p)
		g << -1;
	else
		g << nr - 1;
	return	0;
}