Find the sum of all the prime numbers larger than 2 less than 10^12 that are 1 more than a perfect square. Because the number can get pretty big provide the answer mod 1007.
Note: Problem shouldn't take much more than one minute if your answer is taking too long consider looking for optimizations.