【Example 2】Let $[x]$ denote the greatest integer not exceeding the real number $x$. Find the number of roots of the equation $x^{2}-[x]^{2}=(x-[x])^{2}$ in the interval $[1, n]$.
Solution: It is obvious that $x=n$ is a root of the equation. Next, we will separately determine the number of roots of the equation in the intervals $[1,2), [2,3), \cdots, [n-1, n)$. For this purpose, we denote the set of roots in these intervals as $B_{1}, B_{2}, \cdots, B_{n-1}$, i.e., $B_{k}$ represents the set of all roots of the equation in the interval $[k, k+1)$.

Since when $x \in [k, k+1)$, we have $[x]=k$. If we also denote $p=x-[x]$, then $0 \leqslant p<1$. Thus, the original equation can be rewritten as
$$
(k+p)^{2}-[(k+p)]^{2}=p^{2}
$$

which simplifies to
$$
k^{2}+2 k p=\left[k^{2}+2 k p+p^{2}\right]
$$

Noting that $\left[k^{2}+2 k p+p^{2}\right]=k^{2}+\left[2 k p+p^{2}\right]$, the above equation becomes
$$
2 k p=\left[2 k p+p^{2}\right]
$$

The right-hand side of this equation is an integer, so the left-hand side must also be an integer, i.e., $2 k p$ is an integer. Since $k$ is an integer and $0 \leqslant p<1$, the equation can only hold when $p=0, \frac{1}{2 k}, \frac{2}{2 k}, \cdots, \frac{2 k-1}{2 k}$. Therefore, the original equation has exactly
$2 k$ roots in this interval, i.e., $\left|B_{k}\right|=2 k$. Thus, by the principle of addition, the original equation has a total of
$$
\begin{array}{l}
\left|B_{1}\right|+\left|B_{2}\right|+\cdots+\left|B_{n-1}\right|+1 \\
\quad=2+4+\cdots+2(n-1)+1 \\
=n^{2}-n+1
\end{array}
$$

roots in the interval $[1, n]$.
The principle of addition has many other applications. When combined with other mathematical principles, such as the pigeonhole principle, it can lead to many other interesting mathematical propositions. Readers interested in this topic can refer to relevant books, such as "The Pigeonhole Principle" by Chang Gengzhe. The concept of partitioning sets is of great significance in branches of mathematics such as probability theory and is one of the most fundamental concepts in modern mathematics.