Differential equation of the form $x^2y''+(1-2p)xy'+(p^2-q^2)y=x^n$ $$x^2y''+(1-2p)xy'+(p^2-q^2)y=x^n
$$
can be written in the form 
$$
x^a(x^b(x^cy)')'=x^n,
$$
where
$$
a=1+2p\pm q,
b=1\mp2q, c=-p\pm q.
$$
As you can see there are two possible sets of values of $a,b,c$. Both sets of values gives equivalent differential equations, so they should lead to the same general solution.
However, if you try to solve it, you will start by integrating both sides of 
$$
(x^b(x^cy)')'=x^{n-a},
$$
and the antiderivative of RHS is clearly dependent on the value of $n-a$: when $n-a=-1$, RHS will be integrated to give $\ln x$; otherwise it will be $\frac{x^{n-a+1}}{n-a+1}$. Those two cases clearly do NOT lead to the same general solution. Now, I can choose the values of $p,q$ so that $1+2p-q=n+1$ but $1+2p-q\neq n+1$, that is, one possible value of $a$ gives $\ln(x)$ while the other doesn't. So the two values of $a$ lead to different general solutions. However, changing the sign of $q$ does NOT change the differential equation, so how can it lead to a change in general solution? What is wrong?
EDIT: I focus on the value of $p,q$ that gives $\ln x$ only.
 A: Correct the exponent $a=1+p\pm q$.

So continue to carry out the integration for the general case $(n-p)^2\ne q^2$.
$$
x^b(x^cy)'=\frac{x^{n-a+1}}{n-a+1}+C
\\
(x^cy)'=\frac{x^{n-a+1-b}}{n-a+1}+Cx^{-b}
\\
x^cy=\frac{x^{n-a-b+1}}{(n-a+1)(n-a-b+2)}+Cx^{-b+1}+D
\\
y=\frac{x^{n-a-b-c+1}}{(n-a+1)(n-a-b+2)}+Cx^{-b-c+1}+Dx^{-c}
$$
and as $a+b=2+p\mp q$ the factors in the denominator are $n-p\mp q$ and $n-p\pm q$, which is symmetric in the sign before $q$.

The exceptional cases are those where $n+1-a=0\iff n=p\pm q$ or where $n+1-a-b=0\iff n=p\mp q$.
The first case $n+1-a=0$ gives in the first integration
$$
x^b(x^cy)'=\ln x+C.
$$
The second integration proceeds via partial integration to 
$$
x^cy=Cx^{1-b}+\int x^{-b}\ln x\,dx=Cx^{1-b}+\frac{x^{1-b}\ln x}{1-b}-\int \frac{x^{-b}}{1-b}dx
$$
where the last integral can be combined with the first term.
$$
y=Cx^{p\pm q}+Dx^{p\mp q}\pm\frac{x^{p\pm q}\ln x}{2q}=Cx^{p+q}+Dx^{p-q}+\frac{x^n\ln x}{2(n-p)}.
$$
Constants $C,D$ were reassigned and relabeled deliberately from one step to the next.
In the second case $n+2-a-b=0$ the computation branches off from the regular solution at the second integration giving
$$
x^cy=\frac{\ln x}{(n-a+1)}+Cx^{-b+1}+D
\\
y=\frac{x^{p\mp q}\ln x}{n-p\mp q}+Cx^{p\pm q}+Dx^{p\mp q}
=\frac{x^n\ln x}{2(n-p)}+Cx^{p+ q}+Dx^{p- q}
$$
Constants $C,D$ were reassigned and relabeled deliberately from one step to the next.
So indeed both solution variants lead to the same general solution formula.
