projecteuler---->problem=4----Largest palindrome product

来源:互联网 发布:java算法代码例子 编辑:程序博客网 时间:2024/05/23 18:31

title:

Largest palindrome product

Problem 4

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.

翻译;

假如一个数前后掉转后还是同一个数的话,那个数就叫做「回文数」。由两个二位数的积构成的最大回文数是9009 = 91 × 99。

请找出由两个三位数的积构成的最大回文数。

解答:

def isOk(a):n=0b=[0]*100while a>0:b[n]=a%10a /= 10n += 1for i in range(n//2):if b[i]!=b[n-i-1]:return Falsereturn Truem=0for i in range(100,999):for j in range(100,999):if isOk(i*j) :if i*j > m:m = i*j;print m 


0 0
原创粉丝点击