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

EularProject 36:2进制和10进制回文数

时间:2015-07-30 00:50:29      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

华电北风吹
天津大学认知计算与应用重点实验室
完成日期:2015/7/29

Double-base palindromes
Problem 36
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.

Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

(Please note that the palindromic number, in either base, may not include leading zeros.)

Answer:
872187
Completed on Wed, 29 Jul 2015, 16:04

result=0
for i in range(1,1000000):
    a=bin(i)[2::]
    b=a[::-1]
    if a==b:
        a=str(i)
        b=a[::-1]
        if a==b:
            result+=i

print(result)

版权声明:本文为博主原创文章,未经博主允许不得转载。

EularProject 36:2进制和10进制回文数

标签:

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

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