fixed the miss where k>n, still to slow needs fixing, rearrange the code to streamline for p [1..]