cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A236564 Difference between 2^(2n-1) and the nearest square.

Original entry on oeis.org

1, -1, -4, 7, -17, 23, -89, 7, 28, 112, 448, 1792, -4417, 5503, 22012, -4633, -18532, -74128, -296512, 296863, 1187452, -1181833, -4727332, 4817239, 19268956, -17830441, -71321764, 94338007, 377352028, -9092137, -36368548, -145474192, -581896768, -2327587072, -9310348288
Offset: 1

Views

Author

Alex Ratushnyak, Feb 23 2014

Keywords

Comments

The distances of the even powers 2^(2n) to their nearest squares are obviously all zero and therefore skipped.

Examples

			a(1) = 2^1 - 1^2 = 1.
a(2) = 2^3 - 3^2 = -1.
a(3) = 2^5 - 6^2 = 32 - 36 = -4.
		

Crossrefs

Programs

  • Maple
    A236564 := proc(n)
        local x,sq,lo,hi ;
        x := 2^(2*n-1) ;
        sq := isqrt(x) ;
        lo := sq^2 ;
        hi := (sq+1)^2 ;
        if abs(x-lo) < abs(x-hi) then
            x-lo ;
        else
            x-hi ;
        end if;
    end proc: # R. J. Mathar, Mar 13 2014
  • Mathematica
    Table[2^n - Round[Sqrt[2^n]]^2, {n, 1, 79, 2}] (* Alonso del Arte, Feb 23 2014 *)
  • Python
    def isqrt(a):
        sr = 1 << (int.bit_length(int(a)) >> 1)
        while a < sr*sr:  sr>>=1
        b = sr>>1
        while b:
            s = sr + b
            if a >= s*s:  sr = s
            b>>=1
        return sr
    for n in range(47):
        nn = 2**(2*n+1)
        a = isqrt(nn)
        d1 = nn - a*a
        d2 = (a+1)**2 - nn
        if d2 < d1:  d1 = -d2
        print(str(d1), end=',')

Formula

If A201125(n) < A238454(n), a(n) = A201125(n), otherwise a(n) = -A238454(n). [Negative terms are for cases where the nearest square is above 2^(2n-1), not below it.] - Antti Karttunen, Feb 27 2014