Cod sursa(job #364891)

Utilizator iuly2freemanVasiliev Iulian iuly2freeman Data 17 noiembrie 2009 12:44:29
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <cmath>

//#include <iostream>
//using namespace std;

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

long long zeros(long long p)
{
	long long x = 0, s = 0, i = 0;
    do
    {
        s = p / pow(5, ++i);
        x += s;
    } while (s);

	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; //cin >> P;

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