Objective
Given a prime number \$p\$ and an integer \$n \geq 2\$, find a degree-\$n\$ primitive polynomial modulo \$p\$.
Mathematical explanation
When we perform "modular arithmetic" over some prime number \$p\$, addition, subtraction, and multiplication are well-defined. Here, every pair \$a, b\$ of integers is considered to be equal if and only if there exists an integer \$N\$ such that \$a - b = Np\$ holds. So for example, when \$p = 11\$, it holds that \$4 \times 6 = 24 = 24 - 2 \times 11 = 2\$.
We can perform modular arithmetic over the set of polynomials over \$x\$ with integer coefficients as well, by considering modulo up to some prime number \$p\$ and some irreducible polynomial \$P\$ over \$x\$ with degree \$2\$ or more.
It should be noted that the irreducibility of \$P\$ depends on \$p\$. For example, though \$x^2 + 1\$ is irreducible over integers, it is reducible modulo \$2\$ because \$x^2 + 1 = x^2 + 2x + 1 = (x + 1)^2\$.
Finally, the degree-\$n\$ polynomial \$P\$ over \$x\$ is said to be primitive modulo \$p\$ if, up to modulo \$p\$ and \$P(x)\$, \$x^m\$ equals to \$1\$ only when the integer \$m\$ equals to \$0\$ up to modulo \$p^n - 1\$. It should be noted that the existence of such \$P\$ isn't unique for the given \$n\$.
I/O format
The outputted polynomial \$P\$ shall have integer coefficients that are at least \$0\$ and less than \$p\$. It's not required to have leading coefficient of \$1\$.
Otherwise flexible.
Examples
Input p, Input n, possible Output
2, 2, x^2 + x + 1
2, 3, x^3 + x + 1
2, 4, x^4 + x + 1
3, 2, x^2 + x + 2
3, 3, x^3 + 2x + 1
Notable non-example
Though \$x^2 + 1\$ is irreducible modulo \$3\$, it is not primitive because: $$ x^4 = x^4 + x^2 + 1 = x^2(x^2 + 1) + 1 = 1 $$ and \$4 \neq 0\$ up to modulo \$3^2 - 1 = 8\$.