Cod sursa(job #1965881)

Utilizator YouDontNeedMyNameJurcut Paul YouDontNeedMyName Data 14 aprilie 2017 18:09:57
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int st,dr,n,mid,x,p,sol;
int f(int x)
{
    int z = 5;
    int t = 0;
    while (x/z)
    {
        t += x/z;
        z *= 5;
    }
    return t;
}
int main()
{
    in >> n;
    st = 1;
    dr = 1000000000;
    sol = -1;
    while (st <= dr)
    {
        mid = (st+dr)/2;
        x = f(mid);
        if (x < n)
            st = mid+1;
        else
            if (x > n)
                dr = mid-1;
            else
            {
                sol = mid;
                dr = mid-1;
            }
    }
    out << sol;
    return 0;
}