prime implementation