If $n = p_1^{a_1} \cdots p_r^{a_r}$ the set of nilpotents of $\mathbb{Z}_n$ is $(p_1\cdots p_r)\Bbb Z_n$ Suppose $n = p_1^{a_1} \cdots p_r^{a_r}$ where $p_i$'s are prime integers and $a_i$'s are positive integers.
(a) Show that the set of nilpotent elements in $\mathbb{Z}_n$ is $(p_1\cdots p_r)$, the ideal generated by the element $p_1\cdots p_r$.
(b) Find a necessary and sufficient condition on $n$ such that $\mathbb{Z}_n$ does not have any non-zero nilpotent elements.
My attempt:
(a) Let $x$ be a nilpotent element in $\mathbb{Z}_n$. Then $x^k = n$ for some $k > 0$.Note that $x \neq 1$. Since $\mathbb Z$ is a UFD, $x =  p_1^{b_1} ... p_r^{b_r}$, where $b_i > 0$ and so $x^k = p_1^{k b_1} ... p_r^{k b_r} = p_1^{k b_1 - 1} ... p_r^{k b_r - 1}(p_1 ... p_r) \in (p_1 ... p_r)$. Hence the set of nilpotent elements is a subset of $(p_1 ... p_r)$. On the other hand, for all $x \in (p_1 ... p_r)$, $x = z_1 \cdot p_1 ... p_r \cdot z_2$ for some $z_1 = p_1^{c_1} ... p_r^{c_r}, z_2 = p_1^{d_1} ... p_r^{d_r} \in \mathbb{Z}_n$, so $x = p_1^{c_1 + d_1 +1} ... p_r^{c_r + d_r+1}$. Let k be an natural number such that $k(c_i+d_i+1) >a_i$ for all i. Then we have $x^k = p_1^{k(c_1 + d_1 +1)} ... p_r^{k(c_r + d_r+1)} = p_1^{a_1} ... p_r^{a_r}(p_1^{k(c_1 + d_1 +1)-a_1} ... p_r^{k(c_r + d_r+1)-a_r}) = 0 \in\mathbb{Z}_n$. Hence the $(p_1 ...p_r) \subseteq$ the set of nilpotent elements in $\mathbb{Z}_n$. Therefore $(p_1 ...p_r) =$ the set of nilpotent elements in $\mathbb{Z}_n$
(b) $a_i = 1$ for all $i$. If $a_i = 1$ for all i, then it is obvious then $\mathbb{Z}_n$ does not have any non-zero nilpotent elements. Now I just need to show that if $\mathbb{Z}_n$ does not have any non-zero nilpotent elements, then $a_i = 1$ for all $i$. Proof by contradiction: Suppose there exists some $a_i$ > 1. Then $p_1...p_r < n$ is non-zero a nilpotent element.
 A: You can do lengthy computations with elements, or avoid them.

First the method without computations. If $R$ is a commutative ring and $I$ is an ideal of $R$, then the prime ideals of $R/I$ are of the form $P/I$, where $P$ is a prime ideal of $R$ and $I\subseteq P$. Moreover, the ideal of nilpotent elements is the intersection of all prime ideals.
Indeed, an ideal $R/I$ is of the form $J/I$ with $I\subseteq J$ and $R/J\cong (R/I)/(J/I)$, so $R/J$ is a domain if and only if $(R/J)/(J/I)$ is a domain.
Now the prime ideals of $\mathbb{Z}$ containing $n\mathbb{Z}$ are those of the form $p\mathbb{Z}$, with $p\mid n$. So, in your notation, they are $p_1\mathbb{Z}, p_2\mathbb{Z},\dots,p_r\mathbb{Z}$. Thus the prime ideals of $\mathbb{Z}/n\mathbb{Z}$ are the quotients thereof, so the nilradical of $\mathbb{Z}/n\mathbb{Z}$ is
$$
\bigcap_{1\le i\le r}\frac{p_i\mathbb{Z}}{n\mathbb{Z}}=
\frac{p_1p_2\dots p_r\mathbb{Z}}{n\mathbb{Z}}
$$
This ideal is trivial if and only if $n=p_1p_2\dots p_r$.

The method with computations. Let $[x]$ denote the element in $\mathbb{Z}/n\mathbb{Z}$ corresponding to $x\in\mathbb{Z}$.
In order that $[x]^k=[0]$ for some $k>0$, we need that $n\mid x^k$ and, in particular, that every prime dividing $n$ also divides $x^k$, hence $x$. So, if $[x]$ is nilpotent, $p_1p_2\dots p_r$ divides $x$.
Conversely, if $a=\max\{a_1,a_2,\dots,a_r\}$, we have that
$$
n\mid (p_1p_2\dots p_k)^a
$$
because $p_i^{a_i}$ divides $(p_1p_2\dots p_k)^a$, for $i=1,2,\dots,r$. Thus $[p_1p_2\dots p_r]$ is nilpotent.
Therefore, the ideal generated by $[p_1p_2\dots p_r]$ is nilpotent.
The two inclusions having been proved, we have that the nilradical is the ideal generated by $[p_1p_2\dots p_k]$.
Finally, if $a>1$, the ideal generated by $[p_1p_2\dots p_r]$ is a nonzero ideal of $\mathbb{Z}/n\mathbb{Z}$, so the ring $\mathbb{Z}/n\mathbb{Z}$ has no nonzero nilpotent element if and only if $n$ is squarefree.
A: The proof can be streamlined: if $\,p_i\,$ are nonassociate primes then their $\rm\color{#c00}{lcm}$ = product so
$$ x^k\!\equiv 0\!\!\!\!\pmod{\!n}\,\Rightarrow\,n\!=\!p_1^{e_1}\cdots p_n^{e_n}\!\mid\! x^k \Rightarrow\, \forall i\!:\ p_i\!\mid x^k\,\overset{p\rm \ prime}\Rightarrow \forall i\!: p_i\!\mid\! x\overset{\rm\color{#c00}{lcm}}\Rightarrow p_1\cdots p_n\!\mid\! x$$
Conversely,  for $\,e > $ all $e_i,\,$ $\ p_1\!\cdots p_n\mid x\,\Rightarrow\, p_1^{e_1}\cdots p_n^{e_n}\mid (p_1\cdots p_n)^e\mid  x^e\Rightarrow\,x^e\equiv 0\pmod{\!n}$
A: You should be a little more careful about the distinction between an element of $\mathbb Z_n$ and an integer in $\mathbb Z$ that represents an element of $\mathbb Z_n$.  You have $x^k = n \ (= 0)$ in $\mathbb Z_n$ but as integers this just means $x^k$ is congruent to $0$ modulo $n$, so $x^k = cn$ for some $c \in \mathbb Z$.  You don't know that $x^k$ equals $n$ identically.  Consequently, you also don't know that $p_1, \ldots, p_r$ are the only prime divisors of $x$, in fact throughout your proof you seem to always assume that these are the only primes that can divide any integer.  This is a mistake, other prime numbers can divide integers that represent nonzero elements of $\mathbb Z_n$.
To get $x \in (p_1\cdots p_r)$ you have to show that as integers $p_1\cdots p_r \ | \ x$.  Do this a single prime at a time instead of trying to work with the prime decomposition of $x$, so show that for $1 \leq i \leq r$ you get $p_i \ | \ x$.  You can use the fact that $p_i \ | \ n$ and $x^k = cn$ to get this.
