Cod sursa(job #3185803)

Utilizator aeandreescuAndreescu Ana-Eliza aeandreescu Data 20 decembrie 2023 14:57:16
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>

using namespace std;

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

const int fmax= 500000000;
const int pmax= 268435456;

int five( int x ) {
    int sol= 0;
    for ( int i= 5; i<=x; i*= 5 ) {
        sol+= x/i;
    }

    return sol;
}

int main() {
    int n;
    fin>>n;

    int sol= pmax;
    for ( int step= pmax; step>0; step>>= 1 ) {
        if ( sol>step && five(sol-step)>=n ) {
            sol-= step;
        }
    }

    if ( five(sol)!=n ) {
        sol= -1;
    }

    fout<<sol<<"\n";

    return 0;
}