Let be $A$ a set. It is endowed with one internal composition law which is also associative, let's say $\cdot$. There are two elements $a_1, \: a_2\in A$, such that:
$$a_1x^na_2=x,\forall\: x\in A$$
Prove that $A$ is monoid.
Regarding this post, I imagine that we can prove it for every $n$ prime number.
Apply the condition for $x=a_1$ to obtain $a_1^{n+1}a_2=a_1\ $ (1) $\,$ and set $e:=a_1^na_2$ so that $$a_1e=a_1\,.$$ Then apply for $x=ea_1$: $$ea_1=a_1(ea_1)^na_2=(a_1e)^na_1a_2=a_1^{n+1}a_2=a_1$$ by (1).
So in particular, $e$ is a left identity for $a_1$, but this suffices to prove it's a left identity for any $x$: $$ex=ea_1x^na_2=a_1x^na_2=x\,.$$ Similarly we can prove that $f=a_1a_2^n$ is a right identity for $a_2$ and hence for all $x$.
By the way, applying the condition for $x=e$ shows that $$e = a_1e^na_2 = a_1a_2\,,$$ as it was known in the comments, and similarly we get that it also equals to $f$.
Going further, applying the hypothesis for $x=a_2a_1$ we obtain $a_2a_1=e^{n+1}=e$, so actually $a_2=a_1^{-1}$.
Let $a=a_1$.
It also follows that the inverse of the automorphism $x\mapsto axa^{-1}$ is the mapping $x\mapsto x^n$, so $$x^n=a^{-1}xa$$ and $a^{n-1}=e$ by (1).
Consequently, $x^{n(n-1)}=x$ for all $x\in A$ and thus $A$ is an inverse monoid, the idempotent belonging to $x$ being $x^{n(n-1)-1}$ and the inverse of $x$ being $x^{n(n-1)-2}$.