OFFSET
1,3
COMMENTS
a(n) = n if and only if n is one less than a power of 2.
A257078(n) = smallest number m such that a(m) = n. - Reinhard Zumkeller, Apr 16 2015
LINKS
Nathaniel Shar, Table of n, a(n) for n = 1..8192
EXAMPLE
a(12) = 4. 12 has two 1's in its binary expansion. The previous entry in the sequence that has two 1's in its binary expansion is 3, which is a(8), so a(12) = 12-8 = 4.
PROG
(PARI) findk(va, n) = {hw = hammingweight(n); for (k=1, n-1, if (hammingweight(va[n-k]) == hw, return (k)); ); return (0); }
lista(nn) = {va = vector(nn); for (n=1, nn, k = findk(va, n); if (k==0, va[n] = n, va[n] = k); print1(va[n], ", "); ); } \\ Michel Marcus, Oct 15 2014
(Perl) my (@a, @mem);
$a[0] = 0;
sub listseq {
my $n = shift;
for (1..$n) {
my $s = digitsum($_);
my $last = $mem[$s]||0;
$a[$_] = $_-$last;
$mem[digitsum($_-$last)] = $_;
}
print "$_ $a[$_]\n" for 1..$n;
}
sub digitsum {
my $n = shift;
my $k = 0;
do {$k += ($n&1)} while $n >>= 1;
return $k;
} # Nathaniel Shar, Oct 15 2014
(Haskell)
a248756 n = a248756_list !! (n-1)
a248756_list = f 1 [] where
f x yvs = fst yw : f (x + 1) (yw:yvs) where
yw = g 1 yvs
g _ [] = (x, h)
g k ((z, w):zws) = if w == h then (k, a000120 k) else g (k + 1) zws
h = a000120 x
-- Reinhard Zumkeller, Apr 16 2015
CROSSREFS
AUTHOR
Nathaniel Shar, Oct 13 2014
STATUS
approved