Cod sursa(job #1681062)

Utilizator dsergiu05Sergiu Druga dsergiu05 Data 9 aprilie 2016 11:21:17
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>

using namespace std;

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

const int nmax=1e8;

int fct(int x) {
    int y=x, sol=0;
    while (y/5!=0) {
        sol+=y/5;
        y/=5;
    }
    return sol;
}

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

    int n2;
    for (n2=1; n2<=nmax; n2*=2) {
    }

    int sol=nmax;
    for (int step=n2; step>0; step/=2) {
        if (sol-step>=1 && fct(sol-step)>=n) {
            sol-=step;
        }
    }
    if (fct(sol)==n) {
        fout<<sol<<"\n";
    } else {
        fout<<-1<<"\n";
    }

    return 0;
}