Improved efficiency of prime validation