Cod sursa(job #2120830)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 2 februarie 2018 22:27:39
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
#define ll long long
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
ll nrz(ll x)
{
    ll k=0,c=5;
    while(c<=x)
    {
        k+=x/c;
        c*=5;
    }
    return k;
}
int main()
{
    ll n;
    fin >> n;
    ll k=n;
    if(n==0)
        fout <<"1";
    else
    {
        bool ok=true;
        int i=n+n-nrz(5*k);
        k=i;
        while(nrz(5*k)!=n)
        {
             k+=(n-nrz(5*k));
             if(i==k)
             {
                 ok=false;
                 break;
             }
        }
        fout <<((ok) ? 5*k:-1);
    }
    return 0;
}