You are viewing a single comment's thread. Return to all comments →
#!/bin/python3 import sys def checkPalindrome(n): number_str = str(n) length = len(number_str) isPalindrome = True if (length % 2 != 0): length -= 1 i = 0 while i < length / 2: if number_str[i] != number_str[len(number_str) - (i + 1)]: isPalindrome = False break i += 1 return isPalindrome def findProduct(n): palindrome = 0 for i in range(101, 1000): for j in range(i, 1000): product = i * j if product >= n or product <= palindrome: continue if checkPalindrome(product): palindrome = product return palindrome t = int(input().strip()) for a0 in range(t): n = int(input().strip()) print(findProduct(n))
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #4: Largest palindrome product
You are viewing a single comment's thread. Return to all comments →
Python 3