Removes redundancy in C++ common prime test function