Factorize integers into their prime factors from the command line. Zero dependencies.
$ prime-factors 360
2 x 2 x 2 x 3 x 3 x 5
$ prime-factors 360 --exponent
2^3 × 3^2 × 5
Need to quickly check prime factors while coding, debugging crypto, or doing math homework? Instead of opening a browser and searching "prime factorization of 1234567", just:
npx @kszongic/prime-factors-cli 1234567
# 127 x 9721- ⚡ Instant — no website, no Python, no calculator app
- 📦 Zero dependencies — installs in under a second
- 🖥️ Cross-platform — Windows, macOS, Linux
- 🔗 Pipe-friendly — JSON output for scripting
npm i -g @kszongic/prime-factors-cliOr run directly without installing:
npx @kszongic/prime-factors-cli 42prime-factors 60
# 2 x 2 x 3 x 5prime-factors 100 72 360
# 100 = 2 x 2 x 5 x 5
# 72 = 2 x 2 x 2 x 3 x 3
# 360 = 2 x 2 x 2 x 3 x 3 x 5prime-factors 360 --exponent
# 2^3 x 3^2 x 5
prime-factors 1000000 --exponent
# 2^6 x 5^6prime-factors 60 --json
# {"input":60,"factors":[2,2,3,5]}
prime-factors 60 --json --exponent
# {"input":60,"factors":{"2":2,"3":1,"5":1}}# Find the largest prime factor
prime-factors 2310 --json | jq '.factors[-1]'
# 11
# Batch factorize from a file
cat numbers.txt | xargs prime-factors --json| Flag | Description |
|---|---|
<number> [number...] |
One or more positive integers to factorize |
--exponent |
Show exponent notation (e.g. 2^3 x 3) |
--json |
Output as JSON (great for piping) |
-h, --help |
Show help |
# Quick check if a number is prime (single factor = prime)
prime-factors 997
# 997
# Just the number itself — it's prime!# Factorize two numbers to find GCD manually
prime-factors 120 84 --exponent
# 120 = 2^3 x 3 x 5
# 84 = 2^2 x 3 x 7
# GCD = 2^2 x 3 = 12# Quick factorization during problem-solving
prime-factors 600851475143{
"scripts": {
"factor": "prime-factors"
}
}Uses trial division — the simplest and most intuitive factorization algorithm:
- Start with the smallest prime (2)
- While the number is divisible, divide and record the factor
- Move to the next candidate
- Stop when the candidate exceeds √n
This is efficient for numbers up to ~10^15. For larger numbers, you'd need more advanced algorithms (Pollard's rho, quadratic sieve), but for CLI use this covers virtually all practical cases.
- Math homework — quick factorization without leaving the terminal
- Cryptography — check if a number is prime, analyze key components
- Competitive programming — fast factor lookup during contests
- Teaching — demonstrate prime factorization interactively
- Number theory exploration — find patterns, verify conjectures
| Tool | Zero deps | Cross-platform | JSON output | Exponent notation | Install |
|---|---|---|---|---|---|
| prime-factors-cli | ✅ | ✅ Win/Mac/Linux | ✅ | ✅ | npx @kszongic/prime-factors-cli |
factor (coreutils) |
N/A | ❌ Unix only | ❌ | ❌ | Built-in (Linux) |
| Python one-liner | N/A | ✅ | Manual | Manual | Requires Python |
| Wolfram Alpha | N/A | ✅ (browser) | API only | ✅ | Browser / API key |
| Online calculators | N/A | ✅ (browser) | ❌ | Varies | None |
- perfect-number-cli — Check if numbers are perfect
- roman-calc-cli — Roman numeral arithmetic
- happy-number-cli — Check happy numbers
- pwd-entropy-cli — Calculate password entropy
- bar-chart-cli — Visualize data in the terminal
MIT © 2026 kszongic