Cod sursa(job #3004065)

Utilizator Dragu_AndiDragu Andrei Dragu_Andi Data 16 martie 2023 09:24:52
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int cnt(int n)
{
    int ans=0;
    while(n>=5)
    {
        ans+=n/5;
        n/=5;
    }
    return ans;
}

int main()
{
    int p;
    fin >> p;
    int st=0, dr=5*p, mij;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        if(p<=cnt(mij)) dr=mij-1;
        else st=mij+1;
    }
    if(p==0) fout << 1;
    else if(cnt(st)==p) fout << st;
    else fout << -1;
    return 0;
}