Cod sursa(job #3280063)

Utilizator ciusMocan Caius cius Data 25 februarie 2025 12:02:01
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,x,l=0,m,r=80000003;
int Zerouri(int n)
{
    int sum=n;
    while(n!=0)
    {
        sum+=n/5;
        n/=5;
    }
    return sum;
}
int main()
{
    fin>>p;
    m=(l+r)/2;
    x=Zerouri(m);
    while(l<=r)
    {
        m=(l+r)/2;
        x=Zerouri(m);
        if(x<p)
            l=m+1;
        else
            r=m-1;
        if(x==p)
            break;
    }
    if(x!=p)
        fout<<-1;
    else if(m==0)
        fout<<1;
    else
        fout<<5*m;
}