def previous_greatest_palindrome(n):
    ns = str(n)
    k = len(ns)
    if ns == f"1{'0' * (k - 2)}1":
        return int("9" * (k - 1))
    if k % 2 == 0:        
        m = int(''.join(map(str, ns[0 : k // 2])))
        u = f"1{'0' * (k // 2 - 1)}"
        if m == int(u) and (r := int(u + u[::-1])) < n:
            return r
        while 1:
            s = str(m)
            r = int(s + s[::-1])
            if r < n:
                return r
            m -= 1
    else:
        m = int(''.join(map(str, ns[0 : k // 2 + 1])))
        while 1:
            s = str(m)
            r = int(s + s[:-1][::-1])
            if r < n:
                return r
            m -= 1


a, b = 33, 47

def solve(a, b):
    n = b * b
    while n >= a * a:
        m = previous_greatest_palindrome(n)
        print(m)
        for o in range(b, a, -1):
            if m % o == 0 and a <= m // o <= b:
                print(o, m // o)
                return m
        n = m
ans = solve(a, b)
print(ans)
# n = b * b
# while n > 1:
#     # num = list(map(int, str(n)))
#     # m = nextPalindrome(num)
#     # print(m)
#     s = str(n)
#     t = s[::-1]
#     if s == t:
#         print(n)
#     # n = int(''.join(map(str, num)))
#     n -= 1

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: