Cod sursa(job #3274987)

Utilizator Antonio8Mincu Antonio Alexandru Antonio8 Data 8 februarie 2025 17:12:42
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
const int VMIN = 1;
const int VMAX = 500000000;
int nr_zero(int n){
    int ct = 0;
    while(n >= 5){
        ct += n / 5;
        n /= 5;
    }
    return ct;
}
int cb(int x){
    int st = VMIN, dr = VMAX, rez = VMAX + 1;
    while(st <= dr){
        int m = (st + dr) / 2;
        if(nr_zero(m) >= x){
            rez = m;
            dr = m - 1;
        } else {
            st = m + 1;
        }
    }
    return rez;
}
int main(){
    int p;
    fin >> p;
    int rez = cb(p);
    if(nr_zero(rez) == p){
        fout << rez;
    } else {
        fout << -1;
    }
    fin.close();
    fout.close();
    return 0;
}