Fermat's Last Theorem, mod n Fermat's Last Theorem, mod n
It is a well known fact that for all integers \$p&gt;2\$, there exist no integers \$x, y, z&gt;0\$ such that \$x^p+y^p=z^p\$. However, this statement is not true in general if we consider the integers modulo \$n\$.
You will be given \$n\$ and \$p\$, which are two positive integers with \$n&gt;1\$. Your task will be to write a function or program to compute all positive integers \$x, y, z&lt;n\$ such that \$(x^p+y^p)\$ and \$z^p\$ give the same remainder when divided by \$n\$.
Input
Any reasonable method of input is allowed. E.g. two separate user inputs, ordered pair, two function parameters, etc.
Output
Any reasonable method of output is valid, it may be produced by a function or output to the screen. The order the triples are listed does not matter. Triples such as (1, 2, 3) and (2, 1, 3) are considered distinct, and all distinct triples should be listed exactly once. No invalid/trivial triples such as (0, 0, 0) should be output.
The numbers \$x, y, z\$ may have any ordering within each of the triples, but that order should be consistent. For example if \$2^p+2^p\$ and \$3^p\$ have the same remainder when divided by \$n\$, you may list this triple as (2, 2, 3) or (3, 2, 2).
Examples
n p -&gt; Possible Output
----------------------------------------------------------------
2 3 -&gt; []
3 3 -&gt; [(1,1,2),(2,2,1)]
3 4 -&gt; []
4 3 -&gt; [(1,2,1),(1,3,2),(2,1,1),(2,2,2),(2,3,3),(3,1,2),(3,2,3)]

Scoring
Shortest code in bytes with no standard loopholes wins.
Julia 1.0, 61 bytes



f(n,p,q=1:n-1)=[(x,y,z) for x=q,y=q,z=q if(x^p+y^p)%n==z^p%n]


-1 thanks to Glen O

Try it online!