Project Euler 808
Project Euler 808
题目
Reversible prime squares
Both \(169\) and \(961\) are the square of a prime. \(169\) is the reverse of \(961\).
We call a number a reversible prime square if:
- It is not a palindrome, and
- It is the square of a prime, and
- Its reverse is also the square of a prime.
\(169\) and \(961\) are not palindromes, so both are reversible prime squares.
Find the sum of the first \(50\) reversible prime squares.
解决方案
直接使用sympy
库中的nextprime
暴力枚举质数进行判断,需要注意不要漏掉第一个条件。
代码
1 | from tools import is_prime, is_square, int_sqrt |