def find_factor(num): for x in range(999, 99, -1): if not (num % x): return x else: return 0 def make_palindrome(): for x in range(999, 99, -1): s = str(x) yield int(s + s[::-1]) for x in make_palindrome(): p = find_factor(x) if p: if 3 == len(str(x // p)): print(x) exit()