Cod sursa(job #3282826)

Utilizator 9onelostSendrescu Tudor-Gabriel 9onelost Data 6 martie 2025 21:59:44
Problema Factorial Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>
using namespace std;

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

int p;

int Count(int n){

    int ret = 0;

    while(n){

        ret+=n/5;

        n/=5;

    }

    return ret;

}

int cautare(int st,int dr){

    int mij, ret=-1;

    while(st<=dr){

        mij = (st+dr)/2;

        if(Count(mij) == p){

            ret = mij;

            dr = mij-1;

        }

        else{

            st = mij+1;

        }

    }

    return ret;

}

int main(){

    fin >> p;

    if(p==0){

        fout << 1;

        return 0;

    }

    int l = 1;

    int r = 5*(p+1);

    fout << cautare(l,r);

    return 0;
}