Cod sursa(job #2156576)

Utilizator YetoAdrian Tonica Yeto Data 8 martie 2018 20:24:13
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
using namespace std;
int p, n, st, dr;

int nrzero(int x)
{
    ///numarul de 0-uri in care se termina x!
    int p=5, cnt=0;
    while (p<=x) {
        cnt+=x/p;
        p=p*5;
    }

    return cnt;
}

int main () {
    ifstream fin ("fact.in");
    ofstream fout ("fact.out");
    fin>>p;
    if (p==0) {
        fout<<1;
        return 0;
    }
    /*
    if (p==1)
        fout
    */
    st=p;
    dr=5*p;
    while (st<=dr) {
        int mid = (st+dr)/2;
        if (nrzero(mid)<p)
            st=mid+1;
        else
            dr=mid-1;
    }

    fout<<st;
    return 0;
}