So, in imperative programming language, I probably would use two nested loops, one for the i's, one for the j's together with a test whether the sum of i plus j is a prime number, and some sort of buffer to collect the results. 