Cod sursa(job #2690375)

Utilizator PopescuMihneaPopescu Mihnea-Valentin PopescuMihnea Data 23 decembrie 2020 19:43:18
Problema Factorial Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("fact.in");
ofstream g ("fact.out");
unsigned long long P,x,nr0,k;
int main()
{
    f>>P;
    if (P==0)
        g<<1;
    else
    {
        x=5*P;
        do
        {
            nr0=0;
            x-=5;
            k=5;
            while(k<=x)
            {
                nr0+=x/k;
                k*=5;
            }
        }while (nr0>P);
        if (nr0==P)
            g<<x;
        else
            g<<-1;
        }

}