Cod sursa(job #2382884)

Utilizator eduardcadarCadar Eduard eduardcadar Data 18 martie 2019 19:20:32
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p,m,st(1),dr=INT_MAX;
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;
}