Cod sursa(job #2941778)

Utilizator TheEpicWipedCreaVlad Chirita Alexandru TheEpicWipedCrea Data 18 noiembrie 2022 11:42:26
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in  ("fact.in");
ofstream out("fact.out");

int verif(int x){
    int nr=0;
    while(x>0){
        nr+=x/5;
        x/=5;
    }
    return nr;
}

int main(){
    int p;
    in>>p;
    if(p==0){
        out<<1;
        return 0;
    }

    int st=1,dr=5*p,rez=-1;
    while(st<=dr){
        int mij=(st+dr)/2;
        int nrz=verif(mij);
        if(nrz==p){
            rez=mij;
        }
        if(nrz<p){
            st=mij+1;
        }
        else{
            dr=mij-1;
        }
    }
    out<<rez;
}