How can $\int_0^x\lfloor t \rfloor^2dt$ be written as $\sum_{j=1}^{\lfloor x - 1 \rfloor} j^2 + q^2r$ Question 6(c) from Section 1.15 Exercises of Apostol's Calculus is the following:

Find all $x > 0$ for which $\int_0^x\lfloor t \rfloor^2dt = 2(x-1).$

A particular piece of reference material solves the problem in this manner:

$\int_0^x\lfloor t \rfloor^2dt = \sum_{j=1}^{\lfloor x - 1 \rfloor} j^2 + q^2r$ where $x = q + r, q \in \mathbb Z^+, 0 \le r < 1$.
$$\int_0^x \lfloor t \rfloor^2dt = \frac{q(q-1)(2q-1)}{6} + q^2r = 2(x-1) = 2(q+r-1) \\ \implies q(q-1)(2q-1) + 6q^2r = 12q +12r -12 \\ \implies x = 1, x = \frac52$$

Now, I understand how $\int_0^x\lfloor t \rfloor^2dt$ can be rewritten with $j=1$ and $\lfloor x - 1 \rfloor$ being the lower and upper limits of summation respectively, for you may remove $0$ from the partition of $[0, x]$ without having any effect on the final integral.
The part I don't understand is where the $x = q + r$ expression, and the term $q^2 r$ come into it. I don't understand the effect they have or why they are used. I also feel like adding the $q^2 r$ term to the formula for the square series would not be allowed, for you aren't adding to both sides.
Note that this is not a homework question, I am rather attempting to self-study Calculus over the Summer.
I would appreciate any help you could provide. Thank you.

Note that $$\int_{0}^{x}\lfloor t \rfloor^2 dt = \int_{0}^{\lfloor x \rfloor}\lfloor t \rfloor^2 dt + \int_{\lfloor x \rfloor}^{x}\lfloor t \rfloor^2 dt.$$
The first sum is given by the summation, and the second term is 
$$\int_{\lfloor x \rfloor}^{x}\lfloor t \rfloor^2 dt = \int_{\lfloor x \rfloor}^{x}\lfloor x \rfloor^2 dt = \lfloor x \rfloor^2(x-\lfloor x \rfloor) = q^2r.$$
Here, I have used the fact that $\lfloor t \rfloor = \lfloor x \rfloor$ for $\lfloor x \rfloor \le t \le x$, $q = \lfloor x \rfloor$, and $x = q+r$.
