A326729 a(0) = 0; for n >= 1, a(n) is the result of inverting s-th bit (from right) in n, where s is the number of ones in the binary representation of n.
0, 0, 3, 1, 5, 7, 4, 3, 9, 11, 8, 15, 14, 9, 10, 7, 17, 19, 16, 23, 22, 17, 18, 31, 26, 29, 30, 19, 24, 21, 22, 15, 33, 35, 32, 39, 38, 33, 34, 47, 42, 45, 46, 35, 40, 37, 38, 63, 50, 53, 54, 59, 48, 61, 62, 39, 60, 49, 50, 43, 52, 45, 46, 31, 65, 67, 64, 71, 70, 65, 66, 79, 74, 77, 78, 67, 72, 69, 70, 95, 82, 85, 86, 91, 80, 93, 94, 71, 92, 81, 82, 75, 84, 77, 78, 127, 98, 101, 102, 107, 96
Offset: 0
Links
- Robert Israel, Table of n, a(n) for n = 0..10000
- International Mathematical Olympiad, Problem 5 of IMO 2019.
- Index to sequences related to Olympiads.
Programs
-
Maple
f:= proc(n) local s; s:= convert(convert(n,base,2),`+`); Bits:-Xor(n,2^(s-1)) end proc: f(0):= 0: map(f, [$0..100]); # Robert Israel, Oct 01 2020
-
PARI
A326729(n) = if(n==0,return(0)); bitxor(n,2^(hammingweight(n)-1));
Formula
For n>=1, a(n) = n XOR 2^(A000120(n)-1).
From Robert Israel, Oct 01 2020: (Start)
a(2*n+1) = 2*a(n).
a(2*n + 2^k) = 2*a(n)+2^k if 2^k > 2*n. (End)
Comments