Cod sursa(job #2367068)

Utilizator JohnnyTTache Radu Ioan JohnnyT Data 5 martie 2019 08:14:58
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream>
#include <climits>

using namespace std;

unsigned int p;

unsigned int f(unsigned int a){
    if(a < 5){
        return 0;
    }
    return a / 5 + f(a / 5);
}

int main(){
    fstream f("fact.in", fstream::in);
    f >> p;
    f.close();
    unsigned long long a = 0, b = UINT_MAX;
    unsigned int c;
    while(a != b){
        c = (a + b + 1) / 2;
        if(f(c) < p){
            a = c;
        }
        else{
            b = c - 1;
        }
    }
    f.open("fact.out", fstream::out);
    f << a + 1;
}