Cod sursa(job #1549394)

Utilizator andrey1440Tuiu Andrei andrey1440 Data 12 decembrie 2015 11:57:49
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    long P;
    long i = 1;
    long j = 5;
    long nr0 = 0;

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

    f >> P;
    while(nr0 < P)
    {

        i = j;
        j += 5;
        nr0++;
        while(i % 25 == 0 && i > 0)
        {
            i /= 5;
            nr0++;
            while(i % 25 == 0 && i > 0)
            {
                i /= 25;
                nr0 += 2;
            }

        }


    }
    if(nr0 == P)
    {
        if(P == 0)
            g << "1";
        else
            g << j-5;
    }

    else
        g << "-1";

    return 0;
}