Cod sursa(job #2793456)

Utilizator chiriacandrei25Chiriac Andrei chiriacandrei25 Data 3 noiembrie 2021 17:39:45
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include<iostream>
#include<fstream>
#include<climits>
using namespace std;
int i, p, sol=-1;

int calc(int x)
{
    long long j = 5;
    int sum = 0;
    while(j <= x)
    {
        sum += x / j;
        j = j * 5;
    }
    return sum;
}

int main()
{
    ifstream cin("fact.in");
    ofstream cout("fact.out");
    cin >> p;
    int st = 1, dr = 500000000;
    while(st <= dr)
    {
        int mij = (st + dr) / 2;
        if(calc(mij) >= p)
        {
            dr = mij - 1;
            if(calc(mij)==p)
            sol = mij;
        }
        else
        {
            st = mij + 1;
        }
    }
    cout << sol;
}