cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A384715 a(n) = Sum_{k=0..n} (binomial(n, k) mod 4).

This page as a plain text file.
%I A384715 #58 Jul 12 2025 20:52:20
%S A384715 1,2,4,8,4,8,12,16,4,8,12,24,12,24,24,32,4,8,12,24,12,24,32,48,12,24,
%T A384715 32,48,24,48,48,64,4,8,12,24,12,24,32,48,12,24,32,64,32,64,64,96,12,
%U A384715 24,32,48,32,64,64,96,24,48,64,96,48,96,96,128,4,8,12,24
%N A384715 a(n) = Sum_{k=0..n} (binomial(n, k) mod 4).
%C A384715 This is a 2-automatic sequence.
%H A384715 David Radcliffe, <a href="/A384715/b384715.txt">Table of n, a(n) for n = 0..10000</a>
%H A384715 Kenneth S. Davis and William A. Webb, <a href="https://www.fq.math.ca/Scanned/29-1/davis.pdf">Pascal's triangle modulo 4</a>, Fib. Quart., 29 (1991), 79-83.
%F A384715 a(n) = A001316(n) * (A033264(n) - A085357(n) + 2) for n > 0.
%F A384715 Recurrences:
%F A384715 a(4n) = a(2n),
%F A384715 a(4n+1) = 2a(2n),
%F A384715 a(8n+2) = a(4n+2) + 2a(2n) - a(2n+1),
%F A384715 a(8n+3) = a(4n+3) + 4a(2n) - 4a(n),
%F A384715 a(8n+6) = a(4n+3) + 2a(4n+2) - 2a(2n+1),
%F A384715 a(8n+7) = 2a(4n+3).
%e A384715 Let b(n) be the binary expansion of n. Then a(n) = (1 + p10 + p11) * 2^c, where c is the number of set bits in b(n), p10 is the number of '10' patterns in b(n), and p11 is 1 or 0 depending on whether the pattern '11' is occurring in b(n) or not. This formula is used by _Chai Wah Wu_ in the Python function below. For instance:
%e A384715   n = 25 -> b(n) = 11001 -> a(n) = (1+1+1) * 2^3 = 24.
%e A384715   n = 26 -> b(n) = 11010 -> a(n) = (1+2+1) * 2^3 = 32.
%e A384715   n = 27 -> b(n) = 11011 -> a(n) = (1+1+1) * 2^4 = 48.
%e A384715 - _Peter Luschny_, Jun 25 2025
%t A384715 A384715[n_] := 2^DigitSum[n, 2]*(StringCount[IntegerString[n, 2], "10"] - Boole[BitAnd[n,2*n] == 0] + 2);
%t A384715 Array[A384715, 100, 0] (* _Paolo Xausa_, Jun 26 2025 *)
%o A384715 (Python)
%o A384715 def A001316(n): return (1 + (n % 2)) * A001316(n // 2) if n else 1
%o A384715 def A033264(n): return (n % 4 == 2) + A033264(n // 2) if n else 0
%o A384715 def A085357(n): return int(n & (n<<1) == 0)
%o A384715 def A384715(n): return A001316(n) * (A033264(n) - A085357(n) + 2)
%o A384715 (Python)
%o A384715 def A384715(n): return (((n>>1)&~n).bit_count()+bool(n&(n<<1))+1)<<n.bit_count() # _Chai Wah Wu_, Jun 25 2025
%o A384715 (Python)
%o A384715 def a(n: int) -> int:  # after _Chai Wah Wu_
%o A384715     b = bin(n)[2:]; p = b.count("10"); q = b.count("11")
%o A384715     return (p + (2 if q else 1)) * 2**n.bit_count()  # _Peter Luschny_, Jun 25 2025
%o A384715 (PARI) a(n) = sum(k=0, n, binomial(n,k)%4); \\ _Michel Marcus_, Jun 25 2025
%Y A384715 Cf. A001316, A014081, A033264, A051638 (mod 3 analog), A085357. Row sums of triangle A034931.
%K A384715 nonn,easy
%O A384715 0,2
%A A384715 _David Radcliffe_, Jun 23 2025