Cod sursa(job #364638)

Utilizator iuly2freemanVasiliev Iulian iuly2freeman Data 16 noiembrie 2009 18:10:36
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
#include <cmath>

std::ifstream fin("fact.in");
std::ofstream fout("fact.out");

long long zeros(long long p)
{
	long long x = 0;
	for (long long i = 1; i <= p; i++)
	{
		x += p / pow(5, i);
	}
	return x;
}

int main(){
	
	long long int P, p, p2, ind;

    fin >> P;
	
	p = 4 * P;
	p = p - p % 5;
	
	p2 = zeros(p);

    while (p2 < P)
	{
		p += 5;
        ind = p;
        while (ind % 5 == 0)
		{
            ind = ind / 5;
            p2++;
        }

	}
	if (p2 > P) p = -1;	
	if (!P) p = 1;

    fout << p;

    fin.close();
    fout.close();
	
	return 0;
}