Cod sursa(job #3142145)

Utilizator TudorAndreiPatrascuTudor Andrei Patrascu TudorAndreiPatrascu Data 19 iulie 2023 15:06:15
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,l,r,m,e,x,s;
bool ok=1;
int main()
{
    fin>>p;
    l=1;
    r=100000005;
    if (p==0) {
        fout<<1;
    }
    else {
        while (l<=r && ok) {
            m=(l+r)/2;
            e=0;
            x=m;
            while (x>0) {
                e+=x;
                x/=5;
            }
            if (e<p) {
                l=m+1;
            }
            else if (e>p) {
                r=m-1;
            }
            else {
                ok=0;
                s=m*5;
            }
        }
        if (ok)
            fout<<-1;
        else fout<<s;
    }
    return 0;
}