Started Python version, with generalization to arbitrary powers of k
Took care of special case k=-1