Prime Factorization
Given a positive integer n, return all its prime factors in ascending order, preserving repeated occurrences. The integer 1 has no prime factors, so return an…
Given a positive integer n, return all its prime factors in ascending order, preserving repeated occurrences. The integer 1 has no prime factors, so return an empty array for 1. Return integers in an array, not a set or formatted string.
1 <= n <= 1,000,000. n is an integer. The result has at most 19 factors.
Example 1: input n = 12; output [2,2,3]. Two occurrences of 2 and one of 3 multiply to 12.
Example 2: input n = 1; output []. One is not prime and has no prime factors.
Example 3: input n = 49; output [7,7]. The square of a prime retains both factor occurrences.
Category: Math & Numbers. Topic: math. Difficulty: Easy. Patterns: math.