Cod sursa(job #2271297)

Utilizator mirceatlxhaha haha mirceatlx Data 28 octombrie 2018 13:04:54
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long nrzero(int x)
{
    long p = 0;
     while( x )
     {
            p += x/5;
            x /= 5;
     }
     return p;
}

long cautare_binara(int y)
{
    long long Sol = -1, Left = 0, Right = 1000000000;
    while(Left <= Right)
    {
        int Mid = (Left+Right) / 2;
        if(nrzero(Mid) == y)
        {
            Sol = Mid;
            break;
        }
        if(nrzero(Mid) > y)
            Right = Mid - 1;
        if(nrzero(Mid) < y)
            Left = Mid + 1;
        if(nrzero(Mid) == y)
            return Mid;
    }
    return Sol;
}

int main()
{
    int N=1,P,i,nrzero=1;
    fin>>P;
    if(P==0)
    {
        fout<<1;
        return 0;
    }
    i=cautare_binara(P);
    if(i==-1)
    {
        fout<<-1;
        return 0;
    }
    for(int j=i;j>=1;j--)
    {
        if(j%5==0)
        {
            fout<<j;
            return 0;
        }
    }
    return 0;
}