Primecoin: Faster version of primality test for miner
Ported from upstream commit 2f65454766.