Cod sursa(job #2260420)

Utilizator ralfd123Amariei Andrei ralfd123 Data 14 octombrie 2018 22:33:52
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int p;

int nr_zero(int n)
{   int nr0=0,p5=5;
    while( n >= p5 )
    {   nr0 += n / p5;
        p5 *= 5;
    }
    return nr0;
}

int binarysearch(int a,int b,int p)
{   int poz=-1;
    while( a <= b )
    {   long m=(a+b)>>1;
        if( nr_zero(m) == p )
        {   poz=m; b=m-1;
        }
        else if( nr_zero(m) > p ) b=m-1;
        else a=m+1;
    }
    return poz;
}

int main()
{   f>>p;

    g<<binarysearch(1,1000000000,p);

g.close();
return 0;
}