Cod sursa(job #3122897)

Utilizator Sorin123-21Enachioiu Sorin-Catalin Sorin123-21 Data 21 aprilie 2023 01:48:43
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>
using namespace std;

ifstream in ("fact.in");
ofstream out("fact.out");

typedef long long ll;
typedef long double ld;

long countZeros(long val){
    long result = 0;

    for(long i=5; i<= val; i*=5)
    {
      result+= val/i;
    }
    return result;
}


long noOfZeros;
long long cautBinar(long long l, long long r){
    if(l > r)
        return l;
    if(l == r)
        return l;

    long long mid = (l+r)/2;
    if(countZeros(mid) >= noOfZeros){
        return cautBinar(l, mid);
    }
    return cautBinar(mid+1, r);

}

void solve(){
    in >> noOfZeros;
    if(noOfZeros == 0){
        out << 1;
        return;
    }
    out << cautBinar(1, 500000000);
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    solve();
    return 0;
}