Cod sursa(job #2427978)

Utilizator ionescuandrei1402Ionescu Andrei ionescuandrei1402 Data 3 iunie 2019 10:56:08
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>

using namespace std;

const int VMAX=500000000;

ifstream in("fact.in");
ofstream out("fact.out");

int nr_zero (int n)
{
    int nr=0;
    while(n>0)
    {
        nr+=n/5;
        n/=5;
    }
    return nr;

}

int main()
{
    int p;
    in>>p;

    int st=1;
    int dr = VMAX;
    while (st < dr)
    {
        int m = (st + dr) / 2;
        if (nr_zero(m)>=p)
        {
            dr = m;
        }
        else
        {
            st = m + 1;
        }
    }
    if (nr_zero(st) != p)
    {
        st = -1;
    }
    out<<st;
    in.close();
    out.close();
    return 0;
}