Answer
a) rattling occurs when $a_{max}\gt g$
b) $f=\frac{1}{2\pi} (\sqrt{\frac{g}{A}})$
Work Step by Step
(a) We know that the pencil experiences $g$ downward and $a_{max}$ upward. If they are synchronized, the pencil doesn't rattle. If $a_{max}$ exceeds $g$ at higher frequencies, then we observe rattling because the gravitational force of the pencil is out of sync with $a_{max}$.
(b) We know that
$a_{max}=A\omega^2$
$\implies A(\frac{2\pi}{T})^2=g$
This simplifies to:
$T=\frac{2\pi }{\sqrt{\frac{g}A}}$
Now $f=\frac{1}{T}$
$\implies f=\frac{\sqrt{g/A}}{2\pi}$
$\implies f=\frac{1}{2\pi} (\sqrt{\frac{g}{A}})$