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.

A331961 a(n) is the greatest square number k such that n AND k = k (where AND denotes the bitwise AND operator).

Original entry on oeis.org

0, 1, 0, 1, 4, 4, 4, 4, 0, 9, 0, 9, 4, 9, 4, 9, 16, 16, 16, 16, 16, 16, 16, 16, 16, 25, 16, 25, 16, 25, 16, 25, 0, 1, 0, 1, 36, 36, 36, 36, 0, 9, 0, 9, 36, 36, 36, 36, 16, 49, 16, 49, 36, 49, 36, 49, 16, 49, 16, 49, 36, 49, 36, 49, 64, 64, 64, 64, 64, 64, 64
Offset: 0

Views

Author

Rémy Sigrist, Feb 02 2020

Keywords

Examples

			The first terms, alongside the binary representations of n and of a(n), are:
  n   a(n)  bin(n)  bin(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     1       1          1
   2     0      10          0
   3     1      11          1
   4     4     100        100
   5     4     101        100
   6     4     110        100
   7     4     111        100
   8     0    1000          0
   9     9    1001       1001
  10     0    1010          0
  11     9    1011       1001
  12     4    1100        100
  13     9    1101       1001
  14     4    1110        100
  15     9    1111       1001
  16    16   10000      10000
		

Crossrefs

Programs

  • PARI
    a(n) = forstep (m=sqrtint(n), 0, -1, if (bitand(n, m^2)==m^2, return (m^2)))
    
  • Python
    from math import isqrt
    def A331961(n): return next(m for m in (k**2 for k in range(isqrt(n),-1,-1)) if n&m==m) # Chai Wah Wu, Aug 22 2023

Formula

a(n) = 0 iff n belongs to A062880.
a(n^2) = n^2.