Mai intai trebuie sa te autentifici.

Cod sursa(job #2377190)

Utilizator v31nEftenie Alexandru-Daniel v31n Data 8 martie 2019 22:59:30
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <bits/stdc++.h>
using namespace std;

int P;

int nrzerouri(int n) {
    int pow=5;
    int getzeros = 0;
    while(pow <= n) {
        getzeros += n/pow;
        pow*=5;
    }
    return getzeros;
}

int cautBinar(int l, int r) {
    while(l<r) {
        int m = (l+r)/2;
        if(nrzerouri(m) >= P) r=m;
        else l=m+1;
    }
    return l;
}


int main()
{
    ///
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>P;
    if(P==0)
    {
        g<<1;
        return 0;
    }

    int nr = cautBinar(1, 500000000);
    if( P == nrzerouri(nr) ) g << nr;
        else g << -1;
    ///
    return 0;
}