Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.3 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a15cadf5f240d05a2649558 Challenge 314: Prime Factorization 29 challenge-314

--description--

Given an integer greater than 1, return its prime factorization as an array of numbers in ascending order.

A prime factorization is the set of prime numbers that multiply together to produce the given integer. Each number has exactly one set. For example, the prime factorization of 20 is [2, 2, 5] because 2 * 2 * 5 = 20.

If the given integer is itself prime, return it in a single-element array.

--hints--

prime_factorization(20) should return [2, 2, 5].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(prime_factorization(20), [2, 2, 5])`)
}})

prime_factorization(17) should return [17].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(prime_factorization(17), [17])`)
}})

prime_factorization(15) should return [3, 5].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(prime_factorization(15), [3, 5])`)
}})

prime_factorization(35) should return [5, 7].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(prime_factorization(35), [5, 7])`)
}})

prime_factorization(999) should return [3, 3, 3, 37].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(prime_factorization(999), [3, 3, 3, 37])`)
}})

prime_factorization(360) should return [2, 2, 2, 3, 3, 5].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(prime_factorization(360), [2, 2, 2, 3, 3, 5])`)
}})

prime_factorization(510510) should return [2, 3, 5, 7, 11, 13, 17].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(prime_factorization(510510), [2, 3, 5, 7, 11, 13, 17])`)
}})

--seed--

--seed-contents--

def prime_factorization(n):

    return n

--solutions--

def prime_factorization(n):
    factors = []
    divisor = 2
    while divisor * divisor <= n:
        while n % divisor == 0:
            factors.append(divisor)
            n //= divisor
        divisor += 1
    if n > 1:
        factors.append(n)
    return factors