Cod sursa(job #1577584)

Utilizator dsergiu05Sergiu Druga dsergiu05 Data 23 ianuarie 2016 16:16:43
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>

using namespace std;

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

const int nmax=100000000;

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

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

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

    int sol=5*nmax;
    for (int step=n2; step>0; step/=2) {
        if (sol-step>=1 && zero(sol-step)>=n) {
            sol=sol-step;
        }
    }

    if (zero(sol)==n) {
        fout<<sol<<"\n";
    } else {
        fout<<"-1\n";
    }

    return 0;
}