Run Details #702
Score
100
Correct (≥100)
1/1
Incorrect (<100)
0
Median Time
10789.0ms
Tokens Used
452
Cost
539µ$
Benchmark:
0305_python_prime_factorization
Run Date: 2026-03-02 23:56:01
Coding question results (1)
0305_python_prime_factorization:0
Correct
Score: 100 • 10789ms • 452 tokens • 539µ$
Question: Write Python 3.12 code only.
Define exactly one function named prime_factors(n).
Return a list of prime factors in ascending order, with repetition.
Raise TypeError if n is not an int.
Raise ValueError if n <= 1.
Do not use any imports (no numpy, requests, or other libraries).
Sandbox note: dunder attribute access is blocked (for example, type(x).__name__). Avoid names/attributes starting with '__'.
Expected output format:
- Return exactly one fenced Markdown code block starting with ```python and ending with ```.
- Put only valid Python code inside that block (no prose before/after).
- Use 4 spaces for indentation (not tabs).
- Do not return JSON and do not wrap code in a "function" key.
Sample input/output behavior:
- prime_factors(36) -> [2, 2, 3, 3]
Task:
Write a Python 3.12 function for prime factorization.
Submitted code
def prime_factors(n):
if not isinstance(n, int):
raise TypeError("Input must be an integer.")
if n <= 1:
raise ValueError("Input must be greater than 1.")
factors = []
# Check for number of 2s that divide n
while n % 2 == 0:
factors.append(2)
n //= 2
# n must be odd at this point, thus a skip of 2 can be used
for i in range(3, int(n**0.5) + 1, 2):
while n % i == 0:
factors.append(i)
n //= i
# This condition is to check if n is a prime number greater than 2
if n > 2:
factors.append(n)
return factors
Test case results
| # | Status | Args | Expected | Actual | Error |
|---|---|---|---|---|---|
| 0 | Pass | [2] |
[2] |
[2] |
- |
| 1 | Pass | [12] |
[2, 2, 3] |
[2, 2, 3] |
- |
| 2 | Pass | [36] |
[2, 2, 3, 3] |
[2, 2, 3, 3] |
- |
| 3 | Pass | [97] |
[97] |
[97] |
- |
| 4 | Pass | [999] |
[3, 3, 3, 37] |
[3, 3, 3, 37] |
- |
| 5 | Pass | [1024] |
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2] |
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2] |
- |
| 6 | Pass | [1] |
ValueError |
ValueError |
- |
| 7 | Pass | [0] |
ValueError |
ValueError |
- |
| 8 | Pass | [-10] |
ValueError |
ValueError |
- |
| 9 | Pass | [3.14] |
['TypeError', 'ValueError'] |
TypeError |
- |