码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-06-07 01:24:27      阅读:398      评论:0      收藏:0      [点我收藏+]

标签:python

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 bubuko.com,布布扣 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 



projecteuler---->problem=4----Largest palindrome product,布布扣,bubuko.com

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

标签:python

原文地址:http://blog.csdn.net/china_zoujinyong/article/details/27342161

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!