Cod sursa(job #3335686)

Utilizator mmateiMatei Barbu mmatei Data 23 ianuarie 2026 10:57:33
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>
#include <climits>
#define LL long long
using namespace std;

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

LL n;
unsigned LL nr;

LL f5(LL x){
    LL nrf=0;
    for(LL i=5;x/i>=1;i*=5){
        nrf=nrf+x/i;
    }
    return nrf;
}

int main()
{
    fin>>n;
    LL st=0,dr=INT_MAX,sol=-1;
    while(st<=dr){
        unsigned LL mid=(st+dr)/2;
        if(f5(mid)>=n){
            sol=mid;
            dr=mid-1;
        }else st=mid+1;
    }
    if(f5(sol)==n){
        fout<<(sol/5)*5;
    }else fout<<-1;
    return 0;
}