Cod sursa(job #2758282)

Utilizator matei.balaur2009Matei Balaur12 matei.balaur2009 Data 9 iunie 2021 15:39:24
Problema Factorial Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;

int bruh(int x) {
    int cnt=0;
    while(x>0) {
        cnt+=x/5;
        x=x/5;
    }
    return cnt;
}
int  main() {
    ifstream cin ("fact.in");
    ofstream cout("fact.out");

    int n, st=0, dr, mid;
    cin>>n;
    dr=n;
    while(dr-st>1) {
        mid=(st+dr)/2;
        if(bruh(mid)<n)
            st=mid;
        else
            dr=mid;
    }
    if(bruh(dr)==n)
        cout<<dr;
    else
        cout<<"-1";

    return 0;
}