Skip to main content
1 of 3

#Pyth, 11 bytes

Ms+Gm_+GdSH 

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

[Explanation coming later]