More efficient prime number detection