Solution (source code)

= Solution

The <centre of a group> is $Z(G)=\{z\in G:zg=gz\text{ for every }g\in G\}$. It is a <normal subgroup>. For $|G|=p^r$ with $r\ge1$, let $G$ act on itself by conjugation. The <orbit-stabilizer theorem> makes the size of the conjugacy class of $g$ equal to $[G:C_G(g)]$, a power of $p$. A class has size one exactly when $g\in Z(G)$; every other class size is divisible by $p$. The <class equation> therefore gives
$$
|G|=|Z(G)|+\sum_{\text{noncentral classes}}[G:C_G(g)],
$$
so $p$ divides $|Z(G)|$. Since the identity belongs to the <centre of a group>, its size is a positive multiple of $p$. This proves the <nontrivial center of a finite p-group>.

If $G/Z(G)$ is cyclic, choose a representative $a$ of a generator. Every element is $a^mz$ for an integer $m$ and $z\in Z(G)$. Any two such elements commute, since their central factors commute with everything and their remaining factors are powers of the same element. Thus $G$ is an <abelian group>, $Z(G)=G$, and \b[the cyclic quotient by the <centre of a group> is trivial].

For a non-<abelian group> of order $p^3$, the <centre of a group> has order $p$, $p^2$ or $p^3$ by the proved result and <Lagrange's theorem>. The last would make the <group> abelian. The middle would make $G/Z(G)$ have prime order and hence cyclic, also making $G$ abelian by the preceding argument. Therefore \b[its centre has order $p$].

Finally write the given upper-unitriangular <matrix> as $M(a,b,c)$. Direct <matrix multiplication> gives
$$
M(a,b,c)M(a',b',c')=M(a+a',\,b+b'+ac',\,c+c').
$$
It commutes with every $M(a',b',c')$ exactly when $ac'=a'c$ for all $a',c'\in F$. Taking $(a',c')=(0,1)$ forces $a=0$, and taking $(1,0)$ forces $c=0$; those conditions also suffice. Thus the <centre of a group> in this <Heisenberg group over a prime field> is
$$
\boxed{Z(G)=\left\{\begin{pmatrix}1&0&b\\0&1&0\\0&0&1\end{pmatrix}:b\in F\right\}.}
$$