login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
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

%I #50 Nov 11 2021 20:39:35

%S 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,

%T 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,

%U 3,6,4,2,15,1,11,3,66,6,1,9,1,6,22,2,4,3,1,2,2,2,6

%N 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.

%C 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.

%C 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, ...

%C 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.

%C 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.

%C 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.

%C Problem: Are there positive integers not occurring in the sequence a(1),a(2),a(3),...?

%H Alois P. Heinz, <a href="/A348516/b348516.txt">Table of n, a(n) for n = 0..19683</a>

%e 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.

%t Array[If[IntegerQ@ Log[3, #], 0, Block[{k = 1}, While[Unequal @@ Most@ DigitCount[#^k, 3], k++]; k]] &, 72] (* _Michael De Vlieger_, Oct 21 2021 *)

%o (Python)

%o h=[0,1,-1]

%o def d(x):

%o y,d=x,0

%o while y>0: d,y=d+h[y%3],y//3

%o return d

%o def a(n):

%o v,a,x=n,0,1

%o while v%3==0: v=v//3

%o if v>1:

%o while d(x)!=0: a,x=a+1,v*x

%o return a

%o (Python)

%o from gmpy2 import digits

%o def A348516(n):

%o k, s = 1, digits(n,3).rstrip('0')

%o if s == '1' or s == '': return 1-len(s)

%o m = int(s,3)

%o mk = m

%o while s.count('1') != s.count('2'): k += 1; mk *= m; s = digits(mk,3)

%o return k # _Chai Wah Wu_, Nov 11 2021

%o (PARI) isp3(n) = my(q); isprimepower(n,&q) && (q==3);

%o isok(k, n) = my(d=digits(n^k, 3)); #select(x->(x==1), d) == #select(x->(x==2), d);

%o a(n) = if ((n==1) || isp3(n), return (0)); my(k=1); while (!isok(k, n), k++); k; \\ _Michel Marcus_, Oct 22 2021

%Y Cf. A039001.

%K nonn,base

%O 0,3

%A _Dimiter Skordev_, Oct 21 2021

%E a(0) from _Michel Marcus_, Nov 11 2021

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified August 26 05:03 EDT 2024. Contains 375454 sequences. (Running on oeis4.)