Prime Factorization - Problem
Write a function that takes a positive integer and returns its prime factorization as a list of prime factors.
Prime factorization breaks down a number into its constituent prime numbers. For example, 12 = 2 × 2 × 3, so the prime factors are [2, 2, 3].
Requirements:
- Return factors in ascending order
- Include repeated factors (e.g., for 12, include both 2's)
- Handle edge cases like prime numbers and small inputs
Input & Output
Example 1 — Basic Composite Number
$
Input:
n = 12
›
Output:
[2, 2, 3]
💡 Note:
12 = 2 × 2 × 3, so the prime factors are [2, 2, 3] in ascending order
Example 2 — Prime Number
$
Input:
n = 17
›
Output:
[17]
💡 Note:
17 is already prime, so it has only itself as a prime factor
Example 3 — Large Factors
$
Input:
n = 60
›
Output:
[2, 2, 3, 5]
💡 Note:
60 = 2 × 2 × 3 × 5, breaking down: 60 → 30 → 15 → 5 → 1
Constraints
- 1 ≤ n ≤ 106
- n is a positive integer
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code