If you're only interested in the means and variances of linear combinations of random variables (where the means, variances, and covariances exist), then consider the following.
Suppose the means and covariances are $\mu$ $\Sigma$, respectively, then the linear combination of the multivariate random variable $X$ and another known vector $\omega$ of the same ...
To incorporate comments, for the sake of completeness:
Of the three current suggestions in the comments and answer, Daniel Lichtblau's is fastest:
DivisorSigmaPrime // ClearAll;
DivisorSigmaPrime[r_, n_Integer] :=
DivisorSigma[r, NestWhile[#/2 &, n, EvenQ]];
It's literally a divide-and-conquer approach, as dividing out twos removes the even divisors.
The issue in your code has to do with not leaving proper spaces between the letters you used. Hence, mathematica recognized $n \pi x$ as one variable.
A nice way to check this in future computations, is to also observe what happens to the colors of the variables when it did not work and when it works. Do you observe anything?
If coded with the proper spaces, ...
This is meant to be just an extensive comment, rather than an answer.
It requires some very minor modification of the accepted answer here to make it work in this example.
Let us assume, that you do NOT want to modify the replacement rule from the link I posted. Hence, you have
Sum[expr1_, iter_List] + Sum[expr2_, iter_List] :>