A348516 a(n) is the least positive integer k such that the base 3 representation of n^k contains equally many 1's and 2's, or 0 if no k with this property exists.
1, 0, 7, 0, 16, 1, 7, 1, 22, 0, 16, 1, 16, 6, 2, 1, 8, 6, 7, 1, 4, 1, 66, 9, 22, 3, 2, 0, 15, 1, 16, 2, 32, 1, 6, 9, 16, 2, 11, 6, 19, 13, 2, 13, 1, 1, 10, 22, 8, 2, 1, 6, 1, 159, 7, 1, 20, 1, 3, 6, 4, 2, 15, 1, 11, 3, 66, 6, 1, 9, 1, 6, 22, 2, 4, 3, 1, 2, 2, 2, 6
Offset: 0
Examples
a(2) = 7 because the base 3 representations of 2^1, 2^2, 2^3, 2^4, 2^5, 2^6 and 2^7 are 2, 11, 22, 121, 1012, 2101 and 11202 respectively.
Links
- Alois P. Heinz, Table of n, a(n) for n = 0..19683
Crossrefs
Cf. A039001.
Programs
-
Mathematica
Array[If[IntegerQ@ Log[3, #], 0, Block[{k = 1}, While[Unequal @@ Most@ DigitCount[#^k, 3], k++]; k]] &, 72] (* Michael De Vlieger, Oct 21 2021 *)
-
PARI
isp3(n) = my(q); isprimepower(n,&q) && (q==3); isok(k, n) = my(d=digits(n^k, 3)); #select(x->(x==1), d) == #select(x->(x==2), d); a(n) = if ((n==1) || isp3(n), return (0)); my(k=1); while (!isok(k, n), k++); k; \\ Michel Marcus, Oct 22 2021
-
Python
h=[0,1,-1] def d(x): y,d=x,0 while y>0: d,y=d+h[y%3],y//3 return d def a(n): v,a,x=n,0,1 while v%3==0: v=v//3 if v>1: while d(x)!=0: a,x=a+1,v*x return a
-
Python
from gmpy2 import digits def A348516(n): k, s = 1, digits(n,3).rstrip('0') if s == '1' or s == '': return 1-len(s) m = int(s,3) mk = m while s.count('1') != s.count('2'): k += 1; mk *= m; s = digits(mk,3) return k # Chai Wah Wu, Nov 11 2021
Extensions
a(0) from Michel Marcus, Nov 11 2021
Comments