> 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/unique-factorization.md).

# 唯一分解定理

### 定理内容

任何一个大于 1 的整数都可以**唯一**地分解为若干素数之积：

`n = p1^a1 × p2^a2 × ... × pk^ak`

其中 pi 为素数，指数 ai 为正整数。这个分解称为**质因数分解**。

### 质因数分解算法

从小到大试除，最多试到 `√n`：

```cpp
void factorize(int n) {
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            cout << i << " ";  // i 是 n 的一个质因子
            n /= i;
        }
    }
    if (n > 1) cout << n << " ";  // 剩下的大素数
}
```

### 用途

* 求约数个数：若 `n = p1^a1 × ... × pk^ak`，则约数个数为 `(a1+1)(a2+1)...(ak+1)`
* 求约数之和：`(1+p1+...+p1^a1) × ... × (1+pk+...+pk^ak)`
* 判断完全平方数、求最大公约数等。

### 示例

`60 = 2² × 3 × 5`，约数个数 = (2+1)×(1+1)×(1+1) = 12。


---

# 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/unique-factorization.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.
