Cod sursa(job #3174905)

Utilizator fortyforBroscoi Mihai fortyfor Data 25 noiembrie 2023 10:47:12
Problema Factorial Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <cmath>
#include <fstream>

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

unsigned long long Zero_La_Final_Fact(unsigned int n) {
    if (n<5) {
        return 0;
    }
    unsigned long long s=0,p=5;
    while (p<=n){
        s+=n/p;
        p*=5;
    }
    return s;
}

int main()
{
    unsigned int p;
    fin >> p;
    unsigned int r=24999999,l=1,probe=(l+r)/2;
    while (l<r) {
        if (Zero_La_Final_Fact(probe)==p) {
            fout << probe-probe%5;
            return 0;
        } else if( Zero_La_Final_Fact(probe)<p) {
            l=probe+5;
        } else if ( Zero_La_Final_Fact(probe)>p) {
            r=probe-5;
        }
        probe=(l+r)/2;
    }
    fout << "-1";
    return 0;
}