pythonblack true returns prime factors of n as a list primefactors0 primefactors100 2 2 5 5 primefactors2560 2 2 2 2 2 2 2 2 2 5 primefactors102 primefactors0 02 x primefactors10241 doctest normalizewhitespace x 2241 5241 true primefactors10354 primefactors hello traceback most recent call last typeerror not supported between instances of int and str primefactors1 2 hello traceback most recent call last typeerror not supported between instances of int and list returns prime factors of n as a list prime_factors 0 prime_factors 100 2 2 5 5 prime_factors 2560 2 2 2 2 2 2 2 2 2 5 prime_factors 10 2 prime_factors 0 02 x prime_factors 10 241 doctest normalize_whitespace x 2 241 5 241 true prime_factors 10 354 prime_factors hello traceback most recent call last typeerror not supported between instances of int and str prime_factors 1 2 hello traceback most recent call last typeerror not supported between instances of int and list
from __future__ import annotations


def prime_factors(n: int) -> list[int]:
    
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors


if __name__ == "__main__":
    import doctest

    doctest.testmod()