Cod sursa(job #3211641)

Utilizator Ionut2212Nedelcu Alexandru Ionut Ionut2212 Data 9 martie 2024 18:50:00
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <iostream>
#include <climits>

using namespace std;
long long int dr = LLONG_MAX, st = 1;
ifstream fin ("fact.in");
ofstream fout("fact.out");
int main()
{
    long long int n, poz, z = 0;
    cin >> n;
    if(n == 0) cout << 1;
    else
    {
        while(st <= dr)
        {
            long long int mij = st + (dr-st)/2;
            long long int sum = 0, x = 5;
            while(x <= mij)
            {
                sum+=mij/x;
                x*=5;
            }
            if(sum < n)
            {
                st = mij + 1;
            }
            else
            {
                if(sum == n) z= 1;
                dr = mij - 1;
            }
        }
    }
    if(z == 1) cout << st;
    else cout << -1;
    return 0;
}