%I #8 Oct 23 2024 00:44:39
%S 1,2,3,2,3,4,3,3,4,4,3,4,3,4,5,3,4,5,2
%N Number of fixed points of f(k) = floor(k^2 / n) mod n^2.
%C 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.
%C 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.
%H An article about the history of the middle-square method: http://bit-player.org/2022/the-middle-of-the-square
%e 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.
%o (Python)
%o def f(b):
%o count = 0
%o for n in range(b*b):
%o val = ((n*n) // b) % (b*b)
%o if n == val:
%o count += 1
%o return count
%K nonn,new
%O 1,2
%A _Allan C. Wechsler_, Oct 22 2024