Cod sursa(job #3244518)

Utilizator gBneFlavius Andronic gBne Data 25 septembrie 2024 09:37:37
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>

using namespace std;

typedef long long ull;

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

ull nrdezero(ull p){
    ull imp = 5, cnt = 0;
    while(p >= imp){
        cnt += (p / imp);
        imp *= 5;
    }
    return cnt;
}

int main()
{
    ull n;
    fin >> n;
    ull st = 1, dr = 9223372036854775807;
    while(st <= dr){
        ull mj = (st + dr) / 2;
        ull ans = nrdezero(mj);
        if(ans >= n){
            dr = mj - 1;
        }
        else{
            st = mj + 1;
        }
    }
    fout << st << '\n';
    return 0;
}