[go: up one dir, main page]

login
Negative integers n such that in balanced ternary representation the number of occurrences of each trit doubles when n is squared.
3

%I #20 May 08 2021 11:23:36

%S -314,-898,-942,-2694,-2824,-2826,-2962,-3014,-3070,-3074,-8066,-8082,

%T -8090,-8096,-8132,-8170,-8224,-8336,-8426,-8434,-8450,-8472,-8478,

%U -8480,-8618,-8656,-8870,-8886,-8918,-9008,-9042,-9210,-9222,-9224,-24198,-24226,-24246

%N Negative integers n such that in balanced ternary representation the number of occurrences of each trit doubles when n is squared.

%H Alois P. Heinz, <a href="/A257868/b257868.txt">Table of n, a(n) for n = 1..10000</a>

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Balanced_ternary">Balanced ternary</a>

%e -898 is in the sequence because -898 = LL10L1L_bal3 and (-898)^2 = 806404 = 1LLLL00L1LLL11_bal3, where L represents (-1).

%p p:= proc(n) local d, m, r; m:=abs(n); r:=0;

%p while m>0 do

%p d:= irem(m, 3, 'm');

%p if d=2 then m:=m+1 fi;

%p r:=r+x^`if`(n>0, d, irem(3-d, 3))

%p od; r

%p end:

%p a:= proc(n) option remember; local k;

%p for k from -1+`if`(n=1, 0, a(n-1)) by -1

%p while p(k)*2<>p(k^2) do od; k

%p end:

%p seq(a(n), n=1..50);

%o (Python)

%o def a(n):

%o s=[]

%o l=[]

%o x=0

%o while n>0:

%o x=n%3

%o n//=3

%o if x==2:

%o x=-1

%o n+=1

%o s.append(x)

%o l.append(-x)

%o return [s, l]

%o print([-n for n in range(1, 25001) if a(n**2)[0].count(-1)==2*a(n)[1].count(-1) and a(n**2)[0].count(1)==2*a(n)[1].count(1) and a(n**2)[0].count(0)==2*a(n)[1].count(0)]) # _Indranil Ghosh_, Jun 07 2017

%Y Cf. A117967, A140267, A061656, A061657, A061658, A061659, A061660, A061661, A061662, A061663, A114258, A257867, A257869.

%K sign,base

%O 1,1

%A _Alois P. Heinz_, May 11 2015