Cod sursa(job #1799915)

Utilizator medicinedoctoralexandru medicinedoctor Data 6 noiembrie 2016 23:39:28
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <iostream>
#include <cmath>

using namespace std;

//ifstream cin("fact.in");
//ofstream cout("fact.out");

int d,p,a=1,b=400000015,c=(a+b)/2;

int nzfx(int x) // Numarul de Zerouri al lui Factorial de X
{
    int c=x/5;
    c+=x/25;
    c+=x/125;
    c+=x/625;
    c+=x/3125;
    c+=x/15625;
    c+=x/78125;
    c+=x/390625;
    c+=x/1953125;
    c+=x/9765625;
    c+=x/48828125;
    c+=x/244140625;
    return c;
}

int f(int x)
{
    return nzfx(x)-p;
}

main()
{
    cin >> p;
    if (f(a)==0) cout << a; else
    if (f(b)==0) cout << b; else
    for ( ; ; )
    {
        c=(a+b)/2;
        d=f(c);
        if (d==0)
        {
            while (f(c)==f(c-1))
            {
                c--;
            }
            cout << c;
            break;
        }
        if (d<p) a=c; else b=c;
    }
}