Cod sursa(job #3174795)

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

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

unsigned long long Binary_Exp(unsigned long long a, unsigned long long b) {
    unsigned long long thing = 1;
    while (b>0){
        if (b&1) {thing*=a;}
        a*=a;
        b >>=1;
    }
    return thing;
}

unsigned int Zero_La_Final_Fact(unsigned int n) {
    if (n<5) {
        return 0;
    }
    unsigned int s=0,p=1;
    while (std::floor(n/Binary_Exp(5,p))>0){
        s+=std::floor(n/Binary_Exp(5,p));
        p++;
    }
    return s;
}

int main()
{
    unsigned int p;
    fin >> p;
    unsigned int Q=1;
    while(Zero_La_Final_Fact(Q)<p) {
        Q++;
    }
    fout << Q;
    return 0;
}