Cod sursa(job #2085049)

Utilizator matei_sirbuMatei Sirbu matei_sirbu Data 9 decembrie 2017 16:52:54
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>

using namespace std;

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


int zero(int n)
    {
        int nr=0;
        while (n>=5)
           {
               nr+=n/5;
               n/=5;
           }
        return nr;
    }


int main()
{
    long long pas, P, r;
    in>> P;
    pas = 1 << 28;
    r=0;
    while (pas!=0)
    {
        if (zero(r+pas)<P)
        {
            r+=pas;
        }
        pas/=2;
    }
    r++;
    if (zero(r) != P)
    {
        r=-1;
    }

    out<< r;
    in.close();
    out.close();
    return 0;
}