Cod sursa(job #2151026)

Utilizator Danut23Termure Danut Valeriu Danut23 Data 3 martie 2018 23:32:52
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>
using namespace std;

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

int main ()
{
    int f = 1, P, ct = 0;

    fin >> P;
    int ok = 0, aux;
    for(int N = 1; N < 10000; N++)
    {
        f = 1;
        for(int j = 1; j <= N; j++)
        {
            f = f * j;
        }

        while(f != 0)
        {
            if(f % 10 == 0)
            {
                ct++;
                f = f / 10;
            }
            else
                break;
        }
        if(ct == P)
        {
            ok = 1;
            aux = N;
            break;
        }

        else
            ct = 0;
    }

    if (ok == 1)
        fout << aux;
    else
        fout <<"-1";

    fin.close();
    fout.close();

    return 0;
}