Cod sursa(job #3314638)

Utilizator Vicentiu123Savu Vicentiu Dorian Vicentiu123 Data 10 octombrie 2025 15:41:51
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>
using namespace std;
int f5(int a){
    if(a>=5){
        return a/5+f5(a/5);
    }
    else{
        return 0;
    }
}
const int LMAX=500000000;
int main()
{
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    int st, dr, p;
    fin>>p;
    st=0;
    dr=LMAX;
    while(st+1<dr){
        int mij=(st+dr)/2;
        if(f5(mij)<p){
            st=mij;
        }
        else{
            dr=mij;
        }
    }
    if(f5(dr)!=p){
        fout<<-1;
    }
    else{
        fout<<dr;
    }
    return 0;
}