> For the complete documentation index, see [llms.txt](https://docs.1l.lol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.1l.lol/number-theory/elementary-number-theory.md).

# 初等数论

### 素数与合数

* **素数**：大于 1 且只有 1 和它本身两个约数的数，如 2、3、5、7。
* **合数**：大于 1 且不是素数的数。**1 既不是素数也不是合数**。
* 2 是唯一偶素数。

### 最大公约数与最小公倍数

* **gcd(a, b)**：最大公约数
* **lcm(a, b)**：最小公倍数，`lcm(a,b) = a / gcd(a,b) * b`（先除后乘防溢出）

### 约数与倍数

* 若 `a % b == 0`，则 b 是 a 的约数（因数），a 是 b 的倍数。
* 一个数约数成对出现，枚举约数只需到 `√n`。

```cpp
// 求 n 的所有约数
for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
        cout << i << " ";
        if (i != n / i) cout << n / i << " ";
    }
}
```

### 同余与模运算

* `a ≡ b (mod m)` 表示 a、b 除以 m 余数相同。
* 运算规则：`(a + b) % m = (a%m + b%m) % m`，减法、乘法同理。
* **除法不满足**，需要求逆元。
* 取模常配合防溢出：`(a * b) % m`。

### 奇偶性

* 奇 ± 奇 = 偶，偶 ± 偶 = 偶，奇 ± 偶 = 奇
* 奇 × 奇 = 奇，其余乘法结果为偶


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.1l.lol/number-theory/elementary-number-theory.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
