Cod sursa(job #679287)

Utilizator psycho21rAbabab psycho21r Data 12 februarie 2012 23:37:39
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 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");
    if(aew(i+1)==n) out << i + 1;
    else out << "-1";
    out.close();
    return 0;
}