Beginning algorithm and function compute Nk