Solution to PRIME1in Python

4M, 4.2s