A226005 Lexicographically earliest sequence such that (a(n), a(n+1)) runs through all the pairs of nonnegative integers exactly once, with the constraint that a(n)=0 iff n is a square.
0, 0, 1, 1, 0, 2, 1, 2, 2, 0, 3, 1, 3, 2, 3, 3, 0, 4, 1, 4, 2, 4, 3, 4, 4, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 0, 8, 1, 8, 2, 8, 3, 8, 4, 8, 5, 8, 6, 8, 7, 8, 8, 0, 9, 1, 9, 2, 9, 3, 9, 4, 9, 5, 9, 6, 9, 7, 9, 8, 9, 9, 0
Offset: 0
Keywords
Examples
a(0)=0. a(1)=0. a(2)>0; (0,1) has not yet been visited, hence a(2)=1. a(3)>0; (1,1) has not yet been visited, hence a(3)=1. a(4)=0. a(5)>0; (0,1) has been visited, but (0,2) has not, hence a(5)=2. a(6)>0; (2,1) has not yet been visited, hence a(6)=1. a(7)>0; (1,1) has been visited, but (1,2) has not, hence a(7)=2. a(8)>0; (2,1) has been visited, but (2,2) has not, hence a(8)=2. a(9)=0. etc.
Links
- Paul Tek, Table of n, a(n) for n = 0..10000
Programs
-
Perl
my @a = (0); foreach my $k (1..10) { push @a => 0, ( map { ($k, $_) } 1..$k-1 ), $k, $k; }
Formula
a(n) = ([sqrt n]^2 + [(n-[sqrt n]^2)/2])/2 - (-1)^(n-[sqrt n]^2)*([sqrt n]^2-[(n-[sqrt n]^2)/2])/2, where [] represents the floor function. - David Adam, Nov 09 2017
Comments