Cod sursa(job #2029239)

Utilizator Andrei.GheorgheAndrei Gheorghe Andrei.Gheorghe Data 29 septembrie 2017 18:45:22
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 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;
}