Measurements of long-range azimuthal anisotropies and associated Fourier coefficients for $pp$ collisions at $\sqrt{s}=5.02$ and $13$ TeV and $p$+Pb collisions at $\sqrt{s_{\mathrm{NN}}}=5.02$ TeV with the ATLAS detector