Need to decompose numbers into their prime factors? The Prime Factorization API breaks down any integer into its prime constituents, returning the complete factorization with exponents and formatted representations.
What is Prime Factorization?
Prime factorization is the process of finding which prime numbers multiply together to make a given number. Every integer greater than 1 has a unique prime factorization (this is the Fundamental Theorem of Arithmetic).
Examples:
- 12 = 2 x 2 x 3 = 2^2 x 3
- 100 = 2 x 2 x 5 x 5 = 2^2 x 5^2
- 17 = 17 (prime, only factor is itself)
How Prime Factorization Works
The API uses efficient factorization algorithms:
Trial Division
For smaller numbers, systematically testing potential prime factors starting from 2.
Pollard's Rho Algorithm
For larger numbers, using probabilistic methods for faster factorization.
Miller-Rabin Primality Test
Quickly determining if remaining factors are prime.
Using the Prime Factorization API
TinyFn provides a simple endpoint for prime factorization:
GET https://api.tinyfn.io/v1/math/prime-factors?number=360
Headers: X-API-Key: your-api-key
{
"number": 360,
"factors": [2, 2, 2, 3, 3, 5],
"unique_factors": [2, 3, 5],
"factorization": {
"2": 3,
"3": 2,
"5": 1
},
"formatted": "2^3 x 3^2 x 5",
"is_prime": false,
"factor_count": 6
}
Parameters
| Parameter | Type | Description |
|---|---|---|
number |
integer | The number to factorize (required, 2 to 10^15) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/math/prime-factors?number=84',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(`Factors: ${data.factors.join(' x ')}`); // 2 x 2 x 3 x 7
console.log(`Formatted: ${data.formatted}`); // 2^2 x 3 x 7
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/math/prime-factors',
headers={'X-API-Key': 'your-api-key'},
params={'number': 1000}
)
data = response.json()
print(f"1000 = {data['formatted']}") # 2^3 x 5^3
print(f"Unique primes: {data['unique_factors']}") # [2, 5]
cURL
curl "https://api.tinyfn.io/v1/math/prime-factors?number=360" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Educational Apps: Teach prime factorization concepts
- Math Homework Helpers: Verify student answers
- Cryptography: Understand number structure for encryption
- GCD/LCM Calculators: Prime factors enable efficient GCD/LCM computation
- Number Theory Research: Analyze properties of integers
Best Practices
- Validate input: Ensure numbers are positive integers greater than 1
- Handle primes: Prime numbers return themselves as the only factor
- Consider size limits: Very large numbers may timeout
- Use appropriate format: Exponential form for display, array for computation
- Cache common factorizations: Small numbers are frequently requested
Try the Prime Factorization API
Get your free API key and start factorizing numbers.
Get Free API Key