# Prime Factorization Calculator

> Decomposes an integer into its prime factors by trial division, tests primality, and derives the number and sum of its divisors from the exponents.

- Calculator id: `prime-factorization` · Category: Math (`math`) · Tool name: `calculate_prime_factorization`
- Canonical page: https://tttkmbb.com/math/prime-factorization · This document: https://tttkmbb.com/math/prime-factorization.md · JSON definition: https://tttkmbb.com/math/prime-factorization.json

## Purpose

Decomposes an integer into its prime factors by trial division, tests primality, and derives the number and sum of its divisors from the exponents.

**Use when:** You need the prime factors of an integer up to 10^12, want to know whether it is prime, or need its divisor count.

**Do not use when:** You need the GCD or LCM of several numbers (use gcd-lcm) or factorials and binomial coefficients (use factorial, combinations-permutations).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `n` | integer |  | required | Integer to factor, from 2 to 1,000,000,000,000. (min 2, max 1000000000000) |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `is_prime` | boolean |  | true when n has no divisors other than 1 and itself. |
| `factors` | number_list |  | Prime factors in ascending order with repetition, e.g. [2, 2, 2, 3, 3, 5]. |
| `factorization` | string |  | Prime-power form, e.g. '2^3 × 3^2 × 5'. |
| `distinct_primes` | number_list |  | Each prime factor once. |
| `divisor_count` | integer |  | τ(n) = Π (kᵢ + 1) over the exponents kᵢ of the factorization. |
| `sum_of_divisors` | integer |  | σ(n) = Π (1 + pᵢ + pᵢ² + … + pᵢ^kᵢ), including 1 and n. |

## Formula

`n = p₁^k₁ × p₂^k₂ × … (trial division by 2, then odd numbers up to √n); τ(n) = Π (kᵢ + 1); σ(n) = Π (pᵢ^(kᵢ+1) − 1) / (pᵢ − 1)`

## Data Sources

- Wikipedia – Integer factorization — https://en.wikipedia.org/wiki/Integer_factorization (reference, retrieved 2026-09-23)
- Wikipedia – Divisor function — https://en.wikipedia.org/wiki/Divisor_function (reference, retrieved 2026-09-23)
- Wolfram MathWorld – Prime Factorization — https://mathworld.wolfram.com/PrimeFactorization.html (reference, retrieved 2026-09-23)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/prime-factorization?n=…`
- `POST https://tttkmbb.com/api/v1/calculate/prime-factorization` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/prime-factorization · OpenAPI operationId `calculate_prime_factorization` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "prime-factorization", "inputs": {…}}`

## Example

- 360: inputs `{"n":360}` → `{"is_prime":false,"factors":[2,2,2,3,3,5],"factorization":"2^3 × 3^2 × 5","distinct_primes":[2,3,5],"divisor_count":24,"sum_of_divisors":1170}`
- 97: inputs `{"n":97}` → `{"is_prime":true,"factors":[97],"factorization":"97","divisor_count":2,"sum_of_divisors":98}`

```
GET https://tttkmbb.com/api/v1/calculate/prime-factorization?n=360
```

## Limitations

You need the GCD or LCM of several numbers (use gcd-lcm) or factorials and binomial coefficients (use factorial, combinations-permutations). All values are computed from the formula above; no measurement or live data is involved.

## FAQ

**Why is 1 not accepted?**

1 is neither prime nor composite and has an empty factorization, so the input must be at least 2.

**How fast is this for large numbers?**

Trial division needs at most about 500,000 divisions for n near 10^12, which takes a few milliseconds; larger inputs are rejected.

## Related

- [GCD and LCM Calculator](https://tttkmbb.com/math/gcd-lcm.md) — Common factors and multiples of several integers.
- [Modulo Calculator](https://tttkmbb.com/math/modulo.md) — Remainders used in divisibility tests.
- [Factorial Calculator](https://tttkmbb.com/math/factorial.md) — Products of consecutive integers.
