首页 > 代码库 > projecteuler---->problem=4----Largest palindrome product

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

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=0
	b=[0]*100
	while a>0:
		b[n]=a%10
		a /= 10
		n += 1
	for i in range(n//2):
		if b[i]!=b[n-i-1]:
			return False	
	return True

m=0
for i in range(100,999):
	for j in range(100,999):
		if isOk(i*j) :
			if i*j > m:
				m = i*j;

print m