Miller's O(NP) algorithm implementation