[go: up one dir, main page]

login
Largest palindromic substring of n^2.
1

%I #13 Nov 05 2020 15:39:45

%S 0,1,4,9,6,5,6,9,6,8,1,121,44,9,9,22,6,9,4,6,4,44,484,9,7,6,676,9,8,8,

%T 9,9,4,9,11,22,9,9,444,5,6,8,7,9,9,202,11,22,4,4,5,6,7,9,9,5,313,9,33,

%U 8,6,7,44,969,9,22,6,44,6,7,9,5,8,9,7,6,77,929

%N Largest palindromic substring of n^2.

%C Leading 0's are not allowed, so a(103) = 9, not 060. - _Robert Israel_, Nov 05 2020

%H Robert Israel, <a href="/A184988/b184988.txt">Table of n, a(n) for n = 0..10000</a>

%F a(n) = A047813(A000290(n)).

%e a(15) = largest palindromic substring of 15^2 = largest palindromic substring of 225 = 22.

%p g:= proc(S) S[1] <> "0" and S = StringTools:-Reverse(S) end proc:

%p f:= proc(n) local S,d,l,i,Q;

%p S:= sprintf("%d",n^2);

%p d:= length(S);

%p for l from d to 1 by -1 do

%p Q:= select(g, [seq(S[i..i+l-1],i=1..d+1-l)]);

%p if Q <> [] then return op(sscanf(max(Q),"%d")) fi

%p od;

%p end proc:

%p f(0):= 0:

%p map(f, [$0..200]); # _Robert Israel_, Nov 05 2020

%Y Cf. A000290, A002113, A047813.

%K nonn,base,easy,look

%O 0,3

%A _Jonathan Vos Post_, Mar 27 2011