create helper functions for prime checking and memoize