login
Characteristic function of the lucky numbers.
17

%I #19 Nov 24 2021 11:37:38

%S 1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,

%T 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,

%U 1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1

%N Characteristic function of the lucky numbers.

%C Is there an efficient formula for this sequence? To wit, is there an algorithm for determining whether n is a lucky or unlucky number which is substantially faster than determining the lucky numbers up to n? - _Charles R Greathouse IV_, Nov 24 2021

%H Antti Karttunen, <a href="/A145649/b145649.txt">Table of n, a(n) for n = 1..100005</a>

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/LuckyNumbers.html">Lucky Numbers</a>

%H <a href="/index/Ch#char_fns">Index entries for characteristic functions</a>

%H <a href="/index/Si#sieve">Index entries for sequences generated by sieves</a>

%F a(A000959(n)) = 1, a(A050505(n)) = 0.

%t luckies = 2 Range[0, 100] + 1;

%t Module[{k, r}, For[k = 2, k<Length[luckies], r = luckies[[k++]]; luckies = ReplacePart[luckies, Table[r*i -> Nothing, {i, 1, Length[luckies]/r}]]]];

%t a[n_ /; 1 <= n <= Last[luckies]] := Boole[MemberQ[luckies, n]];

%t Table[a[n], {n, 1, Last[luckies]}] (* _Jean-François Alcover_, Oct 18 2021, after _Robert Israel_ in A000959 *)

%o (PARI) A145649list(up_to) = { my(u=A000959_upto(up_to), v=vector(up_to)); for(i=1,#u,v[u[i]] = 1); (v); }; \\ See there for A000959_upto(). - _Antti Karttunen_, Sep 27 2019

%Y Cf. A000959 (lucky numbers), A050505 (complement: unlucky numbers).

%Y See also A010051, A192490.

%K nonn

%O 1,1

%A _Reinhard Zumkeller_, Oct 15 2008