Cod sursa(job #1791634)

Utilizator GoogalAbabei Daniel Googal Data 29 octombrie 2016 16:11:51
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>

using namespace std;

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

long long pas,p,r;

int putere(int k)
{
    long long x=5,y=0;
    while(x<=k)
    {
        y+=k/x;
        x*=5;
    }

    return y;
}

int caut(int p)
{
    pas=1<<30;
    while(pas!=0)
    {
        if(putere(r+pas)<p)
            r+=pas;
        pas/=2;
    }
    if(putere(r+1)==p)
        return r+1;
    return -1;
}

int main()
{
    fin>>p;
    fout<<caut(p);
    return 0;
}