Cod sursa(job #3332292)

Utilizator RZV139fjDragomir Ioan Razvan RZV139fj Data 5 ianuarie 2026 21:55:05
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int zero(int x)
{
    int cnt=0;
    while(x)
    {
        x=x/5;
        cnt+=x;
    }
    return cnt;
}
int ans=-1;
int main()
{
    int p=0;
    fin>>p;
    if(p==0)
    {
        fout<<0;
        return 0;
    }
    int st=0;
    int dr=5*p;

    while(st<=dr)
    {
        int mij=(st+dr)/2;
        int zerou=zero(mij);
        if(zerou>=p)
        {
            dr=mij-1;
            if(zerou==p)
                ans=mij;
        }
        else
        {
            st=mij+1;
        }
    }
    fout<<ans;

    return 0;
}