# Calculate the prime factors

We had a prime factorization challenge a while ago, but that challenge is nearly six years old and barely meets our current requirements, so I believe it's time for a new one.

## Challenge

Write a program or function that takes as input an integer greater than 1 and outputs or returns a list of its prime factors.

## Rules

• Input and output may be given by any standard method and in any standard format.
• Duplicate factors must be included in the output.
• The output may be in any order.
• The input will not be less than 2 or more than 231 - 1.
• Built-ins are allowed, but including a non-builtin solution is encouraged.

## Test cases

2 -> 2
3 -> 3
4 -> 2, 2
6 -> 2, 3
8 -> 2, 2, 2
12 -> 2, 2, 3
255 -> 3, 5, 17
256 -> 2, 2, 2, 2, 2, 2, 2, 2
1001 -> 7, 11, 13
223092870 -> 2, 3, 5, 7, 11, 13, 17, 19, 23
2147483646 -> 2, 3, 3, 7, 11, 31, 151, 331
2147483647 -> 2147483647


## Scoring

This is , so the shortest code in bytes wins.

• Would've been much better if you disallowed built-ins. – Buffer Over Read Dec 27 '16 at 0:25
• @TheBitByte Challenges that disallow built-ins are generally looked down upon as Do X without Y challenges, especially since it's sometimes hard to tell whether a solution is technically a built-in. – ETHproductions Dec 27 '16 at 0:29
• Well then, enjoy the influx of <5 byte solutions! As I write this, Pyth already does it in 1 byte. – Buffer Over Read Dec 27 '16 at 0:30
• @TheBitByte Think of it as a language-by-language challenge, primarily. Try to beat Python's solution, or some other language without a builtin. – isaacg Dec 27 '16 at 2:30
• @isaacg Well, language-by-language is a better way of looking at it, I agree. – Buffer Over Read Dec 27 '16 at 2:47

# Gol><>, 19 bytes

IT1WP2K%ZB|:N,:M?t;


Try it online!

## Explanation

IT                  < [n]     read input to n then mark cell (T)
1WP     |         < [n m=2] from 2 onwards (m=1;while m:m++;)
2K%ZB          < [n m+1] copy two elements, mod, break if n%m==0
:N       < [n m] (< where n%m==0) print m with newline
,:M?t; < [n/m] (< new n)        divide, if not 1 redo from T else exit


# Pyt, 1 byte

ḋ


Try it online!

• Unfortunately, the non-built-in solution doesn't work on any number containing a duplicate factor (e.g. 8) – ETHproductions Feb 23 '18 at 5:13
• Yep, you're right. Lemme delete it. – mudkip201 Feb 23 '18 at 13:32

# APL(NARS), 1 char, 2 bytes

π


That is...

• ... rather short? – Jonathan Frech Mar 18 '19 at 9:47
• @JonathanFrech yes it is short... Less than a character should be impossible... – RosLuP Mar 18 '19 at 10:02