欧拉工程第四解

| Comments

第四解:

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers.

解:

1
2
3
4
5
6
7
largestPalindrome = 0
for i in range(100,1000):
    for j in range(100,1000):
        product = i * j
        if int(str(product)[::-1]) == product and product > largestPalindrome:
            largestPalindrome = product
print largestPalindrome

穷举,有没有效率高的办法?