Cod sursa(job #2808299)

Utilizator GuessImHereNowAndy Coste GuessImHereNow Data 24 noiembrie 2021 20:43:15
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<bits/stdc++.h>

using namespace std;

ifstream f("fact.in");
ofstream o("fact.out");

int i, p, n=-1;

int calculare(int x)
{
    long long j = 5;

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

int main()
{

    f >> p;
    int st = 1, dr = 500000000;
    while(st <= dr)
    {
        int mijloc = (st + dr) / 2;
        if(calculare(mijloc) >= p)
        {
            dr = mijloc - 1;
            if(calculare(mijloc)==p)
            n = mijloc;
        }else
        {
            st = mijloc+1;
        }
    }
    o << n;
}