Two solutions to P3.  My initial brute force with prime check is 3a.
3b is the enlightened mathematical version with no prime check (so much faster and more elegant).