Cod sursa(job #1871333)

Utilizator alexsandulescuSandulescu Alexandru alexsandulescu Data 7 februarie 2017 11:42:18
Problema Factorial Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>

using namespace std;

ifstream f ("fact.in");
ofstream g ("fact.out");

int P, st, dr, mij;
int nrz(int x) {
    int pow = 5, rez = 0;
    while(x >= pow) rez += (x / pow), pow *= 5;
    return rez;
}
int main()
{
    f >> P;
    st = 1, dr = 5 * P;
    while(st < dr) {
        mij = (st + dr) / 2;
        if(nrz(mij) < P) st = mij + 1;
        else             dr = mij - 1;
    }
    if(nrz(st) == P) g << st << "\n";
    else             g << "-1\n";
    return 0;
}