login
A387109
Number of entries in the n-th row of Pascal's triangle not divisible by 27.
1
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 10, 20, 30, 19, 26, 33, 28, 32, 36, 25, 32, 39, 32, 37, 42, 39, 42, 45, 40, 44, 48, 45, 48, 51, 50, 52, 54, 19, 38, 57, 34, 47, 60, 49, 56, 63, 40, 53, 66, 51, 60
OFFSET
0,2
PROG
(Python)
import re
from gmpy2 import digits
def A387109(n):
s = digits(n, 3)
n1, n2, n10, n20, n21, n11 = s.count('1'), s.count('2'), s.count('10'), s.count('20'), s.count('21'), len(re.findall('(?=11)', s))
n100, n110, n120, n101, n111, n121 = s.count('100'), s.count('110'), s.count('120'), len(re.findall('(?=101)', s)), len(re.findall('(?=111)', s)), len(re.findall('(?=121)', s))
n200, n201, n210, n211, n220, n221 = s.count('200'), s.count('201'), s.count('210'), s.count('211'), s.count('220'), s.count('221')
c = 144*n10+63*n11+128*(n20+n220)+80*n21+864*n100+216*(n101+n110)+54*n111+96*n120+24*n121+1152*n200+288*(n201+n210+1)+72*n211+32*n221
c += (m:=4*n10+n11)*(96*n20+24*n21+9*m)+16*(4*n20+n21)**2
return (c*3**n2<<n1)//9>>5
KEYWORD
nonn
AUTHOR
Chai Wah Wu, Aug 16 2025
STATUS
approved