Project Euler 348
Project Euler 348
题目
Sum of a square and a cube
Many numbers can be expressed as the sum of a square and a cube. Some of them in more than one way.
Consider the palindromic numbers that can be expressed as the sum of a square and a cube, both greater than \(1\), in exactly \(4\) different ways.
For example, \(5229225\) is a palindromic number and it can be expressed in exactly \(4\) different ways:
\(\begin{aligned} & 2285^2 + 20^3\\ & 2223^2 + 66^3\\ & 1810^2 + 125^3\\ & 1197^2 + 156^3\\ \end{aligned}\)
Find the sum of the five smallest such palindromic numbers.
解决方案
本题的解决方式比直接。先从小到大生成\(2\)位以上的回文数,然后再通过枚举立方数,判断减去后的数是否为平方数即可。
代码
1 |
|