Mean Value of a Multiplicative Function close to $n$ in Terms of the Zeta Function Let $f(n)$ be a multiplicative function defined by $f(p^a)=p^{a-1}(p+1)$, where $p$ is a prime number.  How could I obtain a formula for $$\sum_{n\leq x} f(n)$$ with error term $O(x\log{x})$ and express the main term constant in terms of values of Riemann zeta function?
 A: The following is a more general presentation of a recurring idea which comes up when trying to find the mean value of certain multiplicative functions.  Notice that the exact same steps would give us the result if $f(n)$ was replace by say $\phi(n)$, we would need only modify the calculation for $g(n)$ at the end.
Heuristics: Notice $f(n)\approx n$ so that $\frac{f(n)}{n}\approx 1$.  For functions close to one, convolution with the Möbius function will be close to zero, so we can deal with it easily.  Lets define $g(n)=(\mu*\frac{f(d)}{d})(n)=\sum_{d|n}\frac{f(d)}{d}\mu\left(\frac{n}{d}\right)$ so that $(1*g)(n)=\frac{f(n)}{n}$.  The idea will be to rewrite everything in terms of $g$ since $g(n)$ will be small.
The main sum: We can write $$\sum_{n\leq x}f(n)=\sum_{n\leq x}n\frac{f(n)}{n}=\sum_{n\leq x}n\sum_{d|n}g(d)=\sum_{d\leq x}g(d)\sum_{n\leq x,\ d|n} n$$  $$=\sum_{d\leq x}dg(d)\sum_{n\leq \frac{x}{d}} n=\sum_{d\leq x}dg(d)\frac{\left[\frac{x}{d}\right]^2+\left[\frac{x}{d}\right]}{2}$$ $$=\frac{x^2}{2}\sum_{d\leq x}\frac{g(d)}{d}+O\left(x\sum_{d\leq x}|g(d)|\right).\ \ \ \ \ \ \ \ \ \ (1)$$ The error term comes from using $\left[\frac{x}{d}\right]=\frac{x}{d}+O(1)$, and the fact that $$O\left(\sum_{d\leq x}d|g(d)|\left[\frac{x}{d}\right]\right)=+O\left(x\sum_{d\leq x}|g(d)|\right).$$ Thus we see that $$\sum_{n\leq x} f(n)=\frac{x^2}{2}\sum_{d=1}^\infty\frac{g(d)}{d}+O\left(\frac{x^2}{2}\sum_{d>x}\frac{|g(d)|}{d}+x\sum_{d\leq x}|g(d)|\right).$$ Now, using Rankin's trick let $1>\sigma>0$. Then in the first sum $\frac{x}{d}<\frac{x^\sigma}{d^\sigma}$, and in the second sum $1<\frac{x^\sigma}{d^\sigma}$, and so we obtain our final equation that holds for any $0<\sigma<1$:
$$\sum_{n\leq x}f(n)=\frac{x^2}{2}\sum_{d=1}^\infty\frac{g(d)}{d}+O\left(x^{1+\sigma}\sum_{d=1}^\infty \frac{|g(d)|}{d^\sigma}\right),$$ and we choose $\sigma$ to optimize the error term. (For example, for $f(n)=\phi(n)$, we take $\sigma=\frac{1}{\log x}$.)
Calculating $g(d)$: Notice that $\frac{f(p^a)}{p^a}=\left(1+\frac{1}{p}\right)$.  Then since $g(p^a)=\frac{f(p^a)}{p^a}-\frac{f(p^{a-1})}{p^{a-1}}$ for $a\geq 2$, we see that $g(p^a)=0$ when $a\geq  2$.  When $a=1$ $g(p)=\frac{f(p)}{p}-1=\frac{1}{p}$.  Hence $$g(n)=\frac{\mu(n)^2}{n}.$$  
Putting this together:
Letting $\sigma=\frac{1}{\log x}$ we have by $(1)$ that $$\sum_{n\leq x}f(n)=\frac{x^2}{2} \sum_{d=1}^\infty \frac{\mu(d)^2}{d^2}+O(x\log x).$$
Using Euler products, $$\sum_{d=1}^\infty \frac{\mu(d)^2}{d^2}=\prod_p \left(1+\frac{1}{p^2}\right)=\prod_p \left(1-\frac{1}{p^4}\right)\prod_p \left(1-\frac{1}{p^2}\right)^{-1}=\frac{\zeta(2)}{\zeta(4)}.$$  Thus  $$\sum_{n\leq x}f(n)=x^2 \frac{\zeta(2)}{\zeta(4)}+O(x\log x)=\frac{15}{2\pi^2}x^2+O(x\log x).$$
See also this list of relevant questions:


*

*Multiplicative functions close to $1$.

*Calculating the average of $\text{rad}(n).$

*A complicated sum involving four convolutions of the mobius function.

*The error term that arises when summing the Totient function.

*Averages of certain arithmetic functions.

*The average of the $N^{th}$-powerfree part of $n$.
