Mathematica\'s, PowersRepresentations[n, k, p] solves this problem. Is there a similar function in R?