Cod sursa(job #2622761)

Utilizator StefansenNegulescu Stefan Stefansen Data 1 iunie 2020 19:23:37
Problema Factorial Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<iostream>
#include<algorithm>
#include<fstream>
#include<cmath>

using namespace std;

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

int nr_fact(long long x)
{
   int nr = 0, p = 1, temp = 5;

   while(temp <= x)
   {
       nr += x / temp;
       p++;
       temp = pow(5,p);
   }

   return nr;
}



int main()
{
    long long  N,P;
    bool ok = true;
    f>>P;

    N = P * 5;

    if(P == 0)
        g<<1;
    else
    {

    while(ok)
    {
        if(nr_fact(N-5) == P)
            N -= 5;
        else
            ok = false;
    }

    g<<N;
    }




    f.close();
    g.close();
    return 0;

}