## 定义

Source: wikipedia
Let ${\displaystyle S(n)}$ denote the sum of the digits of ${\displaystyle n}$ and let the composition of ${\displaystyle S(n)}$ be as follows:
$${\displaystyle S^{1}(n)=S(n),\ \ S^{m}(n)=S\left(S^{m-1}(n)\right),\ {\text{for}}\ m\geq 2.}$$
Eventually the sequence ${\displaystyle S^{1}(n),S^{2}(n),S^{3}(n),\dotsb }$ becomes a one digit number. Let ${\displaystyle S^{*}(n)}$ (the digital sum of ${\displaystyle n}$ ) represent this one digit number.

### 简单来说

Example:
$$38 \\\Downarrow \\ 3 + 8 = 11 \\ \Downarrow \\ 1 + 1 = 2$$

## 公式

$$dr(n)=\begin{cases} 0 & \mbox{if}\ n =0 \\ 9 & \mbox{if}\ n \neq 0,\ n \equiv 0 \pmod 9 \\ n \mod 9 & \mbox{if}\ n \not\equiv 0 \pmod 9 \end{cases}$$

or

$$dr(n) = 1 + ((n-1)\mod9)$$

Tip: 为什么不是 $dr(n) = n \mod 9$, 因为直接对9取余结果是$[0, 8]$, 而数根是$[0, 9]。$

## 应用

### checksum

$$dr(sum(a + b +… + n)) = sum(dr(a) + dr(b) + … + dr(n))$$