Cod sursa(job #2156573)

Utilizator YetoAdrian Tonica Yeto Data 8 martie 2018 20:22:49
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 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;

    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;
}