|
|
A370512
|
|
Largest palindromic square which is a concatenation of partitions of n; or 0 if no such number exists.
|
|
1
|
|
|
1, 0, 0, 121, 0, 0, 0, 0, 12321, 0, 0, 0, 121, 0, 0, 121242121, 0, 12321, 5221225, 0, 0, 121, 0, 0, 1212225222121, 0, 12321, 5221225, 0, 0, 10201, 0, 0, 1212225222121, 0, 12122232623222121
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,4
|
|
LINKS
|
|
|
FORMULA
|
If n is a palindromic square, then a(n) >= n.
|
|
EXAMPLE
|
Note that a(4) = a(13) = a(22) = 121 as the digits of 121 can be partitioned as 1+2+1 or 12+1 or 1+21.
|
|
PROG
|
(Python)
from collections import Counter
from operator import itemgetter
from sympy.ntheory.primetest import is_square
from sympy.utilities.iterables import partitions, multiset_permutations
smax, m = 0, 0
for s, p in sorted(partitions(n, size=True), key=itemgetter(0), reverse=True):
if s<smax:
break
q = tuple(Counter(p).elements())
c = sum((Counter(str(d)) for d in q), start=Counter())
if len(tuple(filter(lambda x:x&1, c.values()))) <= 1:
for a in multiset_permutations(q):
if (b:=''.join(str(d) for d in a))==b[::-1] and is_square(k:=int(b)):
m = max(k, m)
if m>0:
smax=s
return m
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,more,base
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|