Project Euler 808 - Reversible Prime Squares

Official link:

Thought Process

Complete brute force approach.

I used my prime sieve and for every prime p I check:

  1. If its square is not a palindrome

  2. If its square reversed is a square number,

    1. If it is, I check if the square root is a prime (I do this using the earlier prime sieve, therefore I do not need to check if each number is prime using a separate function).

After I've gone through all the primes, I sort them and output the sum of the first 50, I needed to sieve up to 5*10^7 to get all the necessary primes.

Interactive Code

Input an integer (yourinput)

Code will output the sum of the first yourinput reversible prime squares using all the primes less than 5*10^6. Take note of the comment, to get the correct answer I used all the primes less than 5*10^7, but to make the interactive code faster I lessened the number of primes