Cod sursa(job #2028232)

Utilizator LXGALXGA a LXGA Data 27 septembrie 2017 15:25:24
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
using namespace std;
std::ifstream cin("fact.in");
std::ofstream cout("fact.out");
int nz(int n)
{
    int k=5,aux,x=0;
    while(k<=n)
    {
        x+=n/k;
        k*=5;
    }
    return x;
}

int main()
{
    int i,p,z,l;
    cin>>p;
    for(i=0;;i+=10000)
    {
        z=nz(i);
        if(z==p)
        {
            if(i==0) i=1;
            cout<<i;
            return 0;
        }
        if(z>p)
        {
            l=i;
            break;
        }
    }
    for(i=l-10000;i<=l;i+=5)
    {
        z=nz(i);
        if(z==p)
        {
            if(i==0) i=1;
            cout<<i;
            return 0;
        }

    }
    cout<<"-1";
    return 0;
}