a113047.txt, Kevin Ryde, June 2021

Sequence A113047 is

    a(n) = C(n) mod 3    for n>=0
         = 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, ...

where

           binomial(3n,n)
    C(n) = --------------   = A001764(n)
               2n+1

Paul Barry conjectured that a(n) != 0 iff n = R(j) where

           3^j - 1
    R(j) = -------   =  A003462(j)    for j>=0
              2
         = ternary 111...111 repunit with j many 1s

This is true, and further the terms a(n)!=0 are a(n)=1, never a(n)=2,
so that a(n) is the characteristic function of the ternary repunits.


It's convenient to take C(n) in the following form (per formula by
Robert Ferreol in A001764),

            B(n)
    C(n) =  ----    where  B(n) = binomial(3n+1,n)  = A045721(n)
            3n+1

3n+1 == 1 mod 3 so it has no effect on the remainder mod 3,

    C(n) == B(n)  mod 3


a(n) = 0 when B(n) is divisible by 3.  Kummer showed that for a given
prime p, the power p^e dividing binomial(x+y,y) is

    e = number of carries occurring when add x + y by digits in base p

B(n) is x = n, y = 2n+1 so that the factors of 3 in B(n) are the
number of carries when adding n and 2n+1 in ternary.


If n has any ternary digit 2 then

    n   =  ...    2     ...     ternary
   2n+1 =  ... [1 or 2] ...

Digit 2 in n becomes either 1 or 2 in 2n+1 (depending on carry from
below when forming 2n+1, and always 2 at the least significant digit).
Digits 2+1 or 2+2 both give a carry and so B(n) has a factor of 3.

If n has a 0 digit with a 1 above then

               v
    n   =  ... 1 0 ...     ternary 1 above 0
   2n+1 =  ... 2 d ...     has either d=0 or d=1

Digits 1 + 2 give a carry so B(n) has a factor of 3.  The 0 in n stops
any carry from below when forming 2n+1, so digit 1 in n doubles to 2
in 2n+1.

This leaves only repunits.  For them,

    n   =    1 1 1 1       ternary repunit n = R(j), j>=0
   2n+1 =  1 0 0 0 0

Each digit position is 0+1 so no carries.  So B(n) has no factor of 3
and a(n) != 0 as per Paul Barry.


To see that a(n) = 1 not 2 when n = R(j), consider the binomial as
three factorials

              (3n+1)!
    B(n) = ------------
           (2n+1)! * n!

The product terms 1*2*3*...*n etc in these factorials have various
factors of 3 but they cancel since B(n) != 0 mod 3.  The remainder
B(n) mod 3 is thus determined by the product of the least significant
non-0 ternary digits of the product terms.

    LNZ(i) = lowest non-0 ternary digit of i

Any product term with LNZ=1 is already 1 mod 3.  Any two LNZ=2
multiply 2*2 == 1 mod 3.  The numerator and denominator can be treated
together since 2 is its own multiplicative inverse,

    2^(-1) == 2 mod 3

So the question is whether an odd or even number of LNZ=2 among all
three factorials.  Let

    twos(n) = number of LNZ(i)=2 among i=1..n inclusive
            = A189672(n)

Clark Kimberling in A189672 gives a recurrence for twos(n), based on
how many i have least significant digit 2, plus how many i have one or
more low 0 digits before LNZ=2,

    twos(n) = twos(floor(n/3)) + floor((n+1)/3)

Expanding repeatedly is the following sum.  Each sum term is how many
of i = 1..n have LNZ=2 with exactly k low 0s below that 2.

                         / floor(n/3^k) + 1 \
    twos(n) = Sum   floor| ---------------- |
              k>=0       \         3        /

For n = R(j), these floors become, written in ternary,

       n = 1111     2n+1 = 10000    3n+1 = 11111     ternary

    twos =  111     twos =  1000    twos =  1111     k=0
          +  11           +  100          +  111     k=1
          +   1           +   10          +   11     ...
                          +    1          +    1

A number in ternary is odd or even according as its number of 1 digits
is odd or even.  The total 1 digits among twos(n), twos(2n+1), and
twos(3n+1) is even since the triangle of 1s in 3n+1 is exactly the
combination of the triangle of 1s in n plus the diagonal in 2n+1.

    twos(n) + twos(2n+1) + twos(3n+1) == 0 mod 2
    so
    B(n) == 1 mod 3 for n = R(j)

------------------------------------------------------------------------------