Cod sursa(job #3211633)

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

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

                dr = mij - 1;
            }
        }
    }
    fout << poz;
    return 0;
}