I'm thinking the result should be: n ^ k for d >= k n ^ k - n ^ (k - d) for d < k