码迷,mamicode.com
首页 > 编程语言 > 详细

欧拉计划(python) problem 4

时间:2015-01-27 09:34:40      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

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.


python code:


import math
sqrt=math.sqrt


def func1(x):
    s=str(x)
    n=int(len(s)/2)
    for i in range(0,n):
        if s[i]!=s[-(i+1)]:
            return 0
    return 1


def func2(x):
    for i in range(100,1000):
        if x%i==0:
            if x/i<1000:
                print(i)
                return 1
    return 0


for i in range(10000,1000000)[::-1]:
    if func1(i)==1:
        if func2(i)==1:
            print(i)
            break


result : 906609

time :  1s

欧拉计划(python) problem 4

标签:

原文地址:http://blog.csdn.net/zhangzhengyi03539/article/details/43160377

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