Find the largest palindrome made from the product of two n-digit numbers.
 Since the result could be very large, you should return the largest palindrome mod 1337.

Example:
Input: 2
Output: 987
Explanation: 99 x 91 = 9009, 9009 % 1337 = 987




Note:
The range of n is [1,8].

Source: leetcode | Difficulty: EASY
Tags: Mathematics

Starter code: class Solution:
    def largestPalindrome(self, n: int) -> int:
        

Solutions:
class Solution:

	def largestPalindrome(self, n):
		A = [0, 9, 987, 123, 597, 677, 1218, 877, 475]
		return A[n]


class Solution:

	def largestPalindrome(self, n):
		return [9, 9009, 906609, 99000099, 9966006699, 999000000999, 99956644665999, 9999000000009999][n - 1] % 1337


class Solution(object):

	def largestPalindrome(self, n):
		if n == 1:
			return 9
		for a in range(2, 9 * 10 ** (n - 1)):
			hi = 10 ** n - a
			lo = int(str(hi)[::-1])
			if a ** 2 - 4 * lo < 0:
				continue
			if (a ** 2 - 4 * lo) ** 0.5 == int((a ** 2 - 4 * lo) ** 0.5):
				return (lo + 10 ** n * (10 ** n - a)) % 1337


class Solution:

	def largestPalindrome(self, n):
		if n == 1:
			return 9
		for a in range(2, 9 * 10 ** (n - 1)):
			upper = 10 ** n - a
			lower = int(str(upper)[::-1])
			delta = a ** 2 - 4 * lower
			if delta >= 0 and int(delta ** 0.5) == delta ** 0.5 and ((a + delta) % 2 == 0):
				return (upper * 10 ** n + lower) % 1337


class Solution:

	def largestPalindrome(self, n):
		top = pow(10, n) - 1
		bot = pow(10, n - 1) - 1
		if n == 1:
			return 9
		if n == 2:
			return 987
		for a in range(2, 9 * 10 ** (n - 1)):
			hi = 10 ** n - a
			lo = int(str(hi)[::-1])
			if a ** 2 - 4 * lo < 0:
				continue
			if (a ** 2 - 4 * lo) ** 0.5 == int((a ** 2 - 4 * lo) ** 0.5):
				return (lo + 10 ** n * (10 ** n - a)) % 1337