Cod sursa(job #3185606)

Utilizator zarichenzara chisevescu zarichen Data 19 decembrie 2023 18:56:53
Problema Factorial Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;
ofstream fout ("fact.out");
ifstream fin ("fact.in");
int main()
{
    int i, p, chestie=5,s=0,l=0,r=2e9,mij=0,poz=0;

    fin >> p;
    poz=0;
    l=0;
    r=2e9;
    while (l<=r)
    {
        mij=(l+r)/2;
        s=0;
        chestie=5;
        while (chestie<=mij)
        {
            s=s+mij/chestie;
            chestie=chestie*5;
        }

        if (s<p)
        {
            l=mij+1;
        }
        else
        {
            poz=mij;
            r=mij-1;
        }
    }
    fout << poz;









    return 0;
}