Cod sursa(job #3326241)

Utilizator Cristian.p08Popescu Cristian Cristian.p08 Data 27 noiembrie 2025 20:31:15
Problema Factorial Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
    int P,k=5,S=0,x=5;
    fin>>P;
    if(P==0)
    {
        fout<<1;
    }
    else
    {
    while(S<P)
    {
        S=0;
        x=5;
        while(k>=x)
        {
            S=S+k/x;
            x=x*5;

        }
        k=k+5;

    }
    if(S==P)
    {
        fout<<k-5;
    }
    else
    {
        fout<<-1;
    }
    }
    return 0;
}