No.4 The largest palindrome made from the product of two 3-digit numbers

Q:
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.

A:
''' method 1
The palindrome can be written as: abccba Which then simpifies to: 100000a + 10000b + 1000c + 100c + 10b + a And then: 100001a + 10010b + 1100c Factoring out 11, you get: 11(9091a + 910b + 100c)
所以一个乘数一定是11的倍数
'''

i= 999
maxNum = 0
while i > 99:
j = 990
while j > 99:
re = i * j
l = str(re)
if l == l[::-1]:
if int(l) > maxNum:
maxNum = int(l)
j -= 11
i -= 1

print "palindrome is %d" %maxNum

'''method 2
强大的精简
'''

max([x*y for x in range(900,1000) for y in range(900,1000) if str(x*y) == str(x*y)[::-1]])

pailndrome is 906609
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值