Cod sursa(job #2367074)

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

using namespace std;

unsigned int p;

unsigned int fct(unsigned int a){
    if(a < 5){
        return 0;
    }
    return a / 5 + fct(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(fct(c) < p){
            a = c;
        }
        else{
            b = c - 1;
        }
    }
    a++;
    f.open("fact.out", fstream::out);
    if(fct(a) != p){
        f << -1;
        return 0;
    }
    f << a + 1;
}