In this problem, you have to calculate the largest palindrome number that can be made from the product of two n-digit integers.
# Python Implementation# functiondef PalindromeProductNumber(n):upperBound = 0lowerBound = 0# Calculating upper boundfor i in range(1, n+1):upperBound =upperBound * 10upperBound =upperBound + 9# Calculating lower boundlowerBound = 1 + lowerBound//10max_prdt = 0for i in range(upperBound,lowerBound-1, -1):for j in range(i,lowerBound-1,-1):# calculating products in a rangeproduct = i * jif (product < max_prdt):breaknumber = productreverse_num = 0# checking whether a number is palindromewhile (number != 0):reverse_num = reverse_num * 10 + number % 10number =number // 10# updating productif (product == reverse_num and product > max_prdt):max_prdt = productreturn max_prdtn = 2print(PalindromeProductNumber(n))
Free Resources