Cod sursa(job #3280639)

Utilizator anatolieursuursu anatolie anatolieursu Data 26 februarie 2025 22:25:06
Problema Factorial Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>

#include <cmath>
using namespace std;

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

#define lol long long

int get_zeros(int n){
    int s=n;
    while(n!=0){
        s += n/5;
        n/=5;
    }
    return s;
}

int main() {
    lol p;
    fin >> p;


    if(!p){
        fout << 1;
        return 0;
    }
    int left=0,right=p*5,ans=-1;
    while(left<=right){
        int mid=(left+right)/2;
        int zeroes=get_zeros(mid);
        if(zeroes==p){
            ans=mid;
            right=mid-1;
        }
        else if(zeroes<p){
            left=mid+1;
        }
        else{
            right=mid-1;
        }
    }
    fout<<ans<<"\n";
}