OFFSET
1,2
COMMENTS
The classic base-B "middle square" technique for generating pseudorandom numbers is to square a seed less than B^2, express it in base B, and extract the middle two digits for the next iterate.
This is a very bad technique: it has many short trajectories ending in fixed points or short cycles. This sequence records the number of fixed points.
LINKS
Andrew Howroyd, Table of n, a(n) for n = 1..5000
Brian Hayes, The Middle of the Square, 2022.
EXAMPLE
For n = 7, 30^2 = 900. Integer-divide this by 7 to get 128, which is 30 mod 49 (7^2). So 30 is a fixed point. Two other fixed points are 0 and 7, so A(7) = 3.
PROG
(Python)
def a(b):
count = 0
for n in range(b*b):
val = ((n*n) // b) % (b*b)
if n == val:
count += 1
return count
print([a(n) for n in range(1, 91)])
(PARI) a(n) = sum(k=0, n^2-1, k^2\n % n^2 == k) \\ Andrew Howroyd, Nov 08 2025
CROSSREFS
KEYWORD
nonn
AUTHOR
Allan C. Wechsler, Oct 22 2024
EXTENSIONS
a(20) onward from Andrew Howroyd, Nov 08 2025
STATUS
approved
