OFFSET
0,3
COMMENTS
a(3*n) = a(n) for any positive integer n because multiplication by 3 does not change the counts of the digits 1 and 2 in the base 3 representation. Hence a(n) reaches any of its values at infinitely many n.
There are infinitely many n with a(n) = 1 that are not divisible by 3, e.g. the numbers of the form (3^m + 2)(3^(m-1) + 3^(m-2) + ... + 3 + 1), m = 1, 2, 3, ...
Of course, a(n^a(n)) = 1 whenever a(n) > 0. More generally, if a(n) = p*q, where p and q are positive integers, then a(n^p) = q (hence any positive divisor of a nonzero term of the sequence is a term too). If a(n) = 0 then a(n^p) = 0 for any positive integer p.
In the absence of a proof that a(n) = 0 only for the numbers n which are powers of 3, it would be desirable to have at least an algorithm whose application to any concrete n answers the question whether a(n) = 0.
Except for the case when the number a(n) is 0, it is the least positive integer k such that n^k is a term of the sequence A039001.
Problem: Are there positive integers not occurring in the sequence a(1),a(2),a(3),...?
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..19683
EXAMPLE
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.
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 *)
PROG
(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
(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
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Dimiter Skordev, Oct 21 2021
EXTENSIONS
a(0) from Michel Marcus, Nov 11 2021
STATUS
approved