Cod sursa(job #1700217)

Utilizator teodoramusatoiuTeodora Musatoiu teodoramusatoiu Data 9 mai 2016 20:36:14
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");

long long p;

int zero(int k)
{
    int s=0;
    while(k>=5)
    {
        s+=k/5;
        k=k/5;
    }
    return s;
}

int main()
{
    in>>p;
    if(p==0)
    {
        out<<1;
        return 0;
    }
    int rez=0;
    int pas=1<<30;
    while(pas!=0)
    {
        if( zero(rez+pas)<p )
        {
            rez+=pas;
        }
        pas/=2;
    }
    if(zero(rez+1)>p)
        out<<"-1";
    else
        out<<rez+1<<'\n';
    return 0;
}