Why solving this differential equation $f(x)=x^3+xf'(x)$ in two ways gives two different answers 
Let $f$ be a real valued differential equation on R , such that $f(1)=1$ and $$f(x)=x^3+xf'(x)$$ then find f(x) (May or May Not be unique) ?

I have solved the question as...(let $y=f(x)$) then -
$$ y= x^3+x\left(\frac{dy}{dx}\right)$$ (equation 1)
Differentiating both sides we get :-
$$-3x=\frac{d^2 y}{d x^2}$$ 
integrating both sides we get (where $C$ is the constant of integration)-
$$\frac{dy}{dx}=\frac{-3x^2}{2} + C$$ (equation 2)
Now There are two ways in which I think I can get $f(x)$
Method 1 : Directly Integrating equation $2$ I get(where $K$ is the constant of integration) -
 $$y=\frac{-x^3}{2} +Cx +K$$
Method 2 : If I put equation $2$ in equation $1$ in place of $\frac{dy}{dx}$  we get -
$$y=\frac{-x^3}{2}+Cx$$ 
So my Question which one of these answers( $1$ Or $2$) is correct...and why is the other one wrong ? Or are both of them Correct and we can't say which one without more initial conditions on $f(x)$ ? Any Hint is appreciated .
 A: When you differentiated both sides, you lost some information - for example, any constants that might have been there were lost. What that means is that the conclusion you got, that $\frac{dy}{dx} = \frac{-3x^2}{2} + C$, is a necessary condition of a solution, but not necessarily sufficient. To take an example, say I wanted to solve $n + 5 = 7$ in integers. I could try taking both sides modulo $5$: then we have $n \equiv 2$ mod $5$. This is certainly necessary (it's true of the correct solution) but it isn't sufficient (there are plenty of things meeting this condition, like $382$, which don't satisfy the equation).
Whenever you're solving a differential equation, plugging it back into the original equation is the right last step - it'll weed out situations like this, and check your work. For example, if you feed in $y = \frac{-x^3}{2} + Cx + K$ into your original differential equation, you'll find that $K$ has to be zero.
A: When you plug both answers into the original differential equation for $f(x)$, you can see that $K=0$, as if $K \neq0$, the given differential equation will not hold. We can see this at a glance by observing that if $K \neq 0$, the left hand side of the original diff eq will have constant term K, but the right side will not, since constant K will dissapear when you compute $f'(x)$. Thus both answers are correct.... so long as k=0.
Edit: as other posters have pointed out, by the fundamental theorem of calculus the derivative and integral are inverse operations. Thus differentiating and then immediatley integrating a function is circular. It gets you back to the original function, except with a loss of information (any constants).
A: The first method is incorrect (it gives the wrong answer) while the second method results in a correct answer but not really justified by what you wrote.
To see the problem with the first method, consider for example the simple equation 
$$ \tag{1} f'(x) \equiv 1. $$
The correct way of solving this equation is by integrating both sides and obtain $f(x) = x + C$ where $C \in \mathbb{R}$ is a single constant of integration. Instead, you have differentiated both sides to obtain the equation
$$ \tag{2} f''(x) \equiv 0. $$
Logically, this means that any solution of equation $(1)$ (assuming it is indeed twice-differentiable) will satisfy equation $(2)$ but solutions of equation $(2)$ won't neccesarily be solutions of equation $(1)$. Indeed, the solutions of equation $(2)$ are of the form $f(x) = Bx + C$ where $B,C \in \mathbb{R}$ and only the solutions in which $B = 0$ also satisfy equation $(1)$. Thus, $(1)$ and $(2)$ are not equivalent!
In general, differentiating an equation results in an inequivalent equation that will have more solutions than the original one and they will need to be "eliminated".
In your case, assume that you have a function $y \colon \mathbb{R} \rightarrow \mathbb{R}$ that satisfies
$$ y(x) = x^3 + xy'(x) \,\,\, \forall x \in \mathbb{R}, \,\,\, y(1) = 1. $$
First, when $x \neq 0$ this can be written as
$$ \frac{y(x) - x^3}{x} = y'(x). $$
This shows that as long as $x \neq 0$, the function $y'(x)$ must be differentiable. Differentiating the original equation on $(0,\infty)$ ($(-\infty,0)$), we get that $y$ must satisfy
$$ y''(x) = -3x. $$
Thus, by integrating $y$ twice, it must be of the form
$$ y(x) = \begin{cases} -\frac{x^3}{2} + Ax + B & x > 0 \\ -\frac{x^3}{2} + Cx + D & x < 0 \end{cases}. $$
By plugging $-\frac{x^3}{2} + Ax + B$ into the original equation, we see that the original equation is satisfied on $(0,\infty)$ if and only if $B = 0$. Similarly, $D = 0$. Since $y(1) = 1$, we must have $A = \frac{3}{2}$ so at this point, we know that $y$ can be of the form
$$ y(x) = \begin{cases} -\frac{x^3}{2} + \frac{3}{2}x & x > 0 \\ -\frac{x^3}{2} + Cx & x < 0 \end{cases}. $$
Since $y$ must be continuous, we must define $y(0) = \lim_{x \to 0^{+}} y(x) = \lim_{x \to 0^{-}} y(x) = 0$. Since $y$ must be differentiable at $x = 0$, we must have $C = \frac{3}{2}$ and thus we have proved that the only solution of the original equation on $\mathbb{R}$ is given by $y(x) = -\frac{x^3}{2} + \frac{3}{2}x$ for all $x \in \mathbb{R}$.
