<s>[INST] How to prove that function $f(p)= \frac{1}{(p^2 - 1)} \sum_{q=3}^p \frac{q^2-3}{q}[q\text{ is prime}]$ is less than 0.3 for all $p$? How to prove that function $f(p)= \frac{1}{(p^2 - 1)} \sum_{q=3}^p \frac{q^2-3}{q}[q\text{ is prime}]$ is less than 0.3 for all $p$?
Let's suppose that we have a function defined as follows:
$f(p) = \frac{1}{(p^2 - 1)} \sum_{q=3}^p \frac{q^2-3}{q}[q\text{ is prime}]$
where $p$ is a prime number and $[...]$ are Iverson brackets.
Here are the first few values of $f(p)$:
$f(3) = \frac{1}{(3^2 - 1)} \times \frac {(3^2-3)}{3}$
$f(3) = \frac{1}{8} \times  \frac{6}{3}$
$f(3) = 0.25$
$f(5) = \frac{1}{(5^2 - 1)} \times [ \frac{(3^2-3)}{3} +\frac{(5^2-3)}{5} ]$
$f(5) = \frac{1}{24} \times [ \frac{6}{3} +\frac{22}{5} ]$
$f(5) = 0.26667$
$f(7) = \frac{1}{(7^2 - 1)} \times [ \frac{(3^2-3)}{3} +\frac{(5^2-3)}{5} +\frac{(7^2-3)}{7}]$
$f(7) = \frac{1}{48} \times [ \frac{6}{3} +\frac{22}{5} +\frac{46}{7}]$
$f(7) = 0.273214286$
$f(11) = \frac{1}{(11^2 - 1)} \times [ \frac{(3^2-3)}{3} +\frac{(5^2-3)}{5} +\frac{(7^2-3)}{7}+\frac{(11^2-3)}{11}]$
$f(11) = \frac{1}{120} \times [ \frac{6}{3} +\frac{22}{5} +\frac{46}{7}+\frac{118}{11}]$
$f(11) = 0.198679654$
How to prove that $f(p)$ is always less than 0.3 for all prime numbers $p$?
I wrote a program to calculate $f(p)$ for the first $1000$ primes up to $p = 7,927$ and graphically it appears to approach $0$ with a maximum value of $0.2732$ at $p=7$. From the graph, it looks like it should be easy, but for some reason, I cannot figure it out.
Notice that $f(3) < f(5) < f(7)$, but $f(7) > f(11)$ so a proof by induction may not work.

 [/INST] $$
\begin{align}
\sum_{q=3}^p\frac{q^2-3}{q}
&=\int_{3^-}^{p^+}\frac{x^2-3}{x}\,\mathrm{d}\pi(x)\\
&=\left[\frac{p^2-3}{p}\pi(p)-2\right]-\int_{3^-}^{p^+}\pi(x)\left(1+\frac3{x^2}\right)\mathrm{d}x\\[3pt]
&=\frac{p^2}{2\log(p)}+\frac{p^2}{4\log(p)^2}+\frac{p^2}{4\log(p)^3}+O\!\left(\frac{p^2}{\log(p)^4}\right)
\end{align}
$$
Thus, we have
$$
\frac1{p^2-1}\sum_{q=3}^p\frac{q^2-3}{q}\sim\frac1{2\log(p)}+\frac1{4\log(p)^2}+\frac1{4\log(p)^3}
$$
whose plot looks like

</s>