Cod sursa(job #3030860)

Utilizator cristiana_6Dode Cristiana cristiana_6 Data 17 martie 2023 22:23:20
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
using namespace std;

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

long long n, st, dr, sol=-1, z, mij;
 
long long zerouri(long long n)
{
    int s=0, d=5;
    while(n/d>0)
    {
        s+=n/d;
        d*=5;
    }
    return s;
}

int main()
{
    fin>>n;
    if(n==0) fout<<1;
    else if(n == 1) fout<<5;
    else
    {
        st=1;
        dr=500000000;
        while(st<=dr)
        {
            mij=(st+dr)/2;
            z=zerouri(mij);
            if(z>n)
                dr=mij-1;
            else if(z<n)
                st=mij+1;
            else
            {
                sol=mij;
                dr=mij-1;
            }
        }
        fout<<sol;
    }
    return 0; 
}