OFFSET
1,1
COMMENTS
The corresponding sequence B is A389390.
EXAMPLE
A = 4176,B = 8793.
Multiset(4176) + Multiset(8793) = {1,4,6,7,3,7,8,9}.
Multiset(4176^2 = 17438976) = {1,7,4,3,8,9,7,6}.
Multiset(8793^2 = 77316849) = {7,7,3,1,6,8,4,9}.
All three multisets are {1,3,4,6,7,7,8,9}.
MATHEMATICA
comp[n_] := If[Min[ DigitCount[n^2] - DigitCount[n]] < 0, {}, Block[{q, co, }, q = Sort@ IntegerDigits[n^2]; co = Join @@ (ConstantArray[First@ #, Max[ Last@#, 0]] & /@ (Tally[q] /. (Tally[ IntegerDigits@ n] /. {w_, h_Integer} :> {w, k_} -> {w, k-h}))); n + 0 Select[FromDigits /@ Permutations@ co, # >= n && Sort@ IntegerDigits[#^2] == q &]]]; Join @@ (comp /@ Range[74000]) (* Giovanni Resta, Oct 02 2025 *)
PROG
(Python)
from collections import Counter
from itertools import count, islice, permutations
from sympy.utilities.iterables import multiset_permutations
def AB_gen(): # generator of terms
for A in count(1):
msA, msA2, msB, bigger = Counter(str(A)), Counter(str(A**2)), [], True
if set(msA) - set(msA2): continue
for e in sorted(msA2):
if msA2[e] < msA[e]:
bigger = False
break
msB.extend([e]*(msA2[e]-msA[e]))
if not bigger or msB == []: continue
for mp in multiset_permutations(msB):
B = int("".join(map(str, mp)))
if B < A: continue
msB2 = Counter(str(B**2))
if msA2 == msB2:
yield A, B
print([A for A, B in islice(AB_gen(), 39)]) # Michael S. Branicky, Oct 02 2025
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Yuto Tsujino, Oct 02 2025
STATUS
approved
