Cod sursa(job #2382878)

Utilizator eduardcadarCadar Eduard eduardcadar Data 18 martie 2019 19:18:00
Problema Factorial Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <cstdlib>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p,m,st(1),dr(100000000);
int zero(int i) {
    int nr=0,x=5;
    while (x<=i) {
        nr+=i/x;
        x*=5;
    }
    return nr;
}
int main()
{
    f>>p;
    if (!p) {
        g<<"1\n";
        exit(0);
    }
    while (st<=dr) {
        m=(st+dr)/2;
        if (zero(m)==p) {
            g<<m-m%5<<'\n';
            exit(0);
        }
        if (zero(m)<p) st=m+1;
        else dr=m-1;
    }
    g<<"-1\n";
    return 0;
}