login
A386395
Smallest final number reachable from n by successively replacing a substring of digits with its square root.
4
1, 2, 3, 2, 5, 6, 7, 8, 3, 10, 11, 12, 13, 12, 15, 2, 17, 18, 13, 20, 21, 22, 23, 22, 5, 26, 27, 28, 23, 30, 31, 32, 33, 32, 35, 6, 37, 38, 33, 20, 21, 22, 23, 22, 5, 26, 27, 28, 7, 50, 51, 52, 53, 52, 55, 56, 57, 58, 53, 60, 61, 62, 63, 8, 65, 66, 67, 68, 63, 70, 71, 72, 73, 72, 75, 76, 77, 78, 73, 80, 3, 82, 83, 82
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
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
Sequence in context: A372379 A350390 A366765 * A361253 A097448 A066729
KEYWORD
nonn,base
AUTHOR
Ali Sada, Jul 20 2025
STATUS
approved