# Return prime factorization of a number [duplicate]

Yes, this is old and probably very simple, but I really want to be mindblown by things that I thought were obvious, so here's the challenge:

You're given a positive integer as the input and you need to output the exponents of all of the prime factors up to the highest factor in base 36 ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c ... z ). If there are some primes in between that are no factors, they have exponent 0. The output must be ordered can be either an array or a string separated by \n, (space) or just outputs from different calls. The program should calculate correctly the output for exponents bigger than 36, but it's not required

Say you're given 42 as the input, its prime factorization is 2*3*7, all of which have 1 as the exponent, but there is also 5 with an exponent of 0, so your output would be [ 1, 1, 0, 1 ] because 2 is the first prime and has an exponent of 1, 3 is the second and has an exponent of 1, 5 is the third and has an exponent of 0 and so on. Here are the correct input/outputs for the first 30 numbers

2   1
3   0 1
4   2
5   0 0 1
6   1 1
7   0 0 0 1
8   3
9   0 2
10  1 0 1
11  0 0 0 0 1
12  2 1
13  0 0 0 0 0 1
14  1 0 0 1
15  0 1 1
16  4
17  0 0 0 0 0 0 1
18  1 2
19  0 0 0 0 0 0 0 1
20  2 0 1
21  0 1 0 1
22  1 0 0 0 1
23  0 0 0 0 0 0 0 0 1
24  3 1
25  0 0 2
26  1 0 0 0 0 1
27  0 3
28  2 0 0 1
29  0 0 0 0 0 0 0 0 0 1
30  1 1 1


and you can find a working expanded version of this on codepen

The solution with the lowest number of bytes wins. Feel free to send in languages who have built-in prime factorization functions, but I won't accept them as answers for pretty obvious reasons. If you send in a solution that doesn't use such functions I'll consider it. It's kind of a grey area, but we'll figure it out.

### Edit:

If it's unclear what do I mean by "base", consider the number 3072. Its prime factors are 2 and 3. 2 has an exponent of 10, so in base 36 that's a. That means that the output would look like this:

a 1


or the number 732421875000 whose factorization is 2^3 * 3^1 * 5^15, whose output would be

3 1 f


## marked as duplicate by trichoplax, DJMcMayhem♦, Alex A. code-golf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Dec 30 '15 at 20:11

• Huh, where does base 36 come in? – xnor Dec 30 '15 at 18:47
• I'd the output is to be base 36, that's totally arbitrary. It's trivial for languages with a built-in and annoyingly tangential otherwise. – xnor Dec 30 '15 at 18:53
• downvoted for requiring base 36. if it's meant to be a twist, it isn't very interesting. also, for what xnor said – quintopia Dec 30 '15 at 18:56
• Also, this might be a dupe of an existing factorization challenge. I wouldn't count just giving exponents or using a base as much different. Could someone please check existing challenges? – xnor Dec 30 '15 at 19:23
• Related (@xnor – Is this the dupe you had in mind?) – Alex A. Dec 30 '15 at 19:33

# Octave, 51 bytes

@(n)dec2base(histc(factor(n),unique(factor(n))),36)


This defines an anonymous function that takes a number and returns a char array. Explanation to come.

# Pyth, 15 bytes

VheSPQIP_NC/PQN


Try it here

Outputs in base 256.

(Base36 version, 33 bytes)

VheSPQIP_NjjkmC++48d*>hdT7j/PQN36


Try it here

(Base 10 version, 14 bytes)

VheSPQIP_N/PQN


Try it here

All versions are separated by newlines. There is some unclearness over whether not base 36 outputs are allowed so I included many versions. Uses factorisation functions and is_prime functions.

• any base above 36 would have been fine :) – towc Dec 30 '15 at 20:04
• Base 256 isn't particularly readable though. – Blue Dec 30 '15 at 20:04

## Mathematica, 80 bytes

#~IntegerExponent~Prime@Range@PrimePi@FactorInteger[#][[-1,1]]~IntegerString~36&


I tried. Without factorization:

## Mathematica, 90 bytes

#~IntegerExponent~Prime@Range@PrimePi@Select[Divisors@#,PrimeQ][[-1,1]]~IntegerString~36&