OFFSET
1,2
COMMENTS
The substring replaced must be a square and cannot begin with a 0 digit.
There may be multiple different replacements possible and the aim is to find whatever steps reach the smallest final value.
The sequence could also start with a(0) = 0. - M. F. Hasler, Sep 23 2025
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..10000
Michael S. Branicky, Scatter plot of n, a(n) for n = 1..10^6.
EXAMPLE
425 -> 25 -> 5.
1004 -> 102.
6251 -> 251 -> 51.
9616 -> 3616 -> 196 -> 136 -> 16 -> 4 -> 2.
9996 -> 9936 -> 996 -> 936 -> 96 -> 36 -> 6.
PROG
(Python)
from functools import cache
from math import isqrt
def children(n):
s = str(n)
return set(int(s[:i]+str(r)+s[j:]) for i in range(len(s)) for j in range(i+1, len(s)+1) if (w:=s[i:j])[0]!='0' and (r:=isqrt(t:=int(w)))**2 == t)
@cache
def a(n): return min((a(c) for c in children(n)-{n}), default=n)
print([a(n) for n in range(1, 85)]) # Michael S. Branicky, Jul 20 2025, edited Sep 28 2025
(PARI) apply( {A386395(n, m=n)=if(n<14, issquare(n, &m), my(d=digits(n)); for(i=1, #d, d[i] && for(j=i, #d, issquare(fromdigits(d[i..j]), &n)&& n>1&& m=min(A386395(fromdigits(concat([d[1..i-1], digits(n), d[j+1..-1]]))), m)))); m}, [0..99]) \\ M. F. Hasler, Sep 23 2025
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Ali Sada, Jul 20 2025
STATUS
approved
