Project Euler 36
Project Euler 36
题目
Double-base palindromes
The decimal number,
Find the sum of all numbers, less than one million, which are
palindromic in base
(Please note that the palindromic number, in either base, may not include leading zeros.)
解决方案
先枚举所有的二进制回文数,再判断其是否为十进制回文数。枚举的过程中,需要分开来考虑生成偶数长度的回文数和奇数长度的回文数。
这将只需要枚举
代码
1 | N = 10 ** 6 |