26 lines
705 B
Python
26 lines
705 B
Python
|
from lib_prime import primes
|
||
|
from lib_misc import is_palindrome_string
|
||
|
|
||
|
|
||
|
def euler_808():
|
||
|
r = []
|
||
|
squared_primes = set()
|
||
|
ps = primes(100000000)
|
||
|
for p in ps:
|
||
|
p_squared = p * p
|
||
|
p_squared_str = str(p_squared)
|
||
|
if not is_palindrome_string(p_squared_str):
|
||
|
squared_primes.add(p_squared)
|
||
|
p_squared_reverse = int(p_squared_str[::-1])
|
||
|
if p_squared_reverse in squared_primes:
|
||
|
r += [p_squared, p_squared_reverse]
|
||
|
if len(r) == 50:
|
||
|
break
|
||
|
return sum(r)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
solution = euler_808()
|
||
|
print("e808.py: " + str(solution))
|
||
|
assert(solution == 3807504276997394)
|