Cod sursa(job #2086502)

Utilizator Seba951Sebastian Boerescu Seba951 Data 12 decembrie 2017 09:37:58
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <fstream>

using namespace std;

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

const int L=28;

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

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