Cod sursa(job #3166131)

Utilizator nicushor21Pirlog Marian Nicolae nicushor21 Data 7 noiembrie 2023 19:06:56
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int p,cnt,i,j,aux,x,st,dr,mid;
int main(){
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    fin>>p;
    if(p!=0){
        st=1; dr=p;
        while(st<=dr){
            mid=(st+dr)/2;
            i=1; cnt=0;
            aux=mid/5;
            while(aux>0){
                cnt+=aux;
                aux/=5;
            }
            aux=mid+cnt;
            if(aux>=p){
                dr=mid-1;
                x=mid;    
            }else{
                st=mid+1;
            }
        }
        x*=5;
        fout<<x;
    } else{
        fout<<1;
    }
    fin.close();
    fout.close();
    return 0;
}