Cod sursa(job #679280)

Utilizator psycho21rAbabab psycho21r Data 12 februarie 2012 23:23:00
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
//Cautare binara dupa ideea originala a lui Mihai Patrascu
#include <fstream>
using namespace std;
long aew(long go)
{
    long r = 0;
    while(go>=1) r+=go/5, go/=5;
    return r;
}
int main()
{
    long n, step, i, abs;
    ifstream in("fact.in"); in >> n; in.close();
    abs = n*5+1;
    for (step = 1; step < abs; step <<= 1);
    for (i = 0; step; step >>= 1)
        if (i + step < abs && aew(i+step) < n) i += step;
    ofstream out("fact.out"); out << i + 1; out.close();
    return 0;
}