[Question]
      [
A while ago, I had a look at the prime factorization of 27000:
>
> 27000 = 23 × 33 × 53
>
>
>
There are two special things about that:
* **consecutive-prime**: The primes are consecutive: 2 is the 1st prime, 3 is the 2nd prime, 5 is the 3rd prime.
* **constant-exponent**: The exponent is the same for every prime (always 3)
Mathematically expressed:
>
> An integer *x* is a consecutive-prime/constant-exponent number if there exist strictly positive integers *n*, *k*, *m* such that *x* = *p**n**m* × *p**n*+1*m* × ... × *p**n*+*k**m*, where *p**j* is the *j*-th prime
>
>
>
Your task is to test if a positive integer fulfills these conditions.
## Input:
A positive integer > 1, in any reasonable form.
## Output:
One of two values, at least one of which has to be constant, indicating whether the input is a consecutive-prime/constant-exponent number.
## Edge cases:
* primes are truthy, as the factorization for prime *p* is *p*1
* other numbers that can be written as *p**m* where *p* is a prime are also truthy.
## Rules:
* Standard loopholes apply.
* No worries about integer overflow, but numbers up to 255 must work.
* Shortest code in bytes wins.
## Test cases:
Truthy:
```
2
3
4
5
6
7
8
9
11
13
15
27000
456533
```
Falsy:
```
10
12
14
72
10000000
```
[Here](https://tio.run/##fVLBboMwDD0nX@FVqkRahoCpm4rGdcedduuqComwRoIQQdDar2cOSTO2tTtAEuf5@T3H6qyPrUzHUTSq7TR0hSzbhlLdDVzzXkMOuz2tirqfHVUnGt6bfRrCQwibEJ5CSBL88JSY/TaEFPfpdk9p1XYgQEg4IfsHD4RUgw4YyyjBMvp4RiZbN7JLwOAZ4mhDyVTpIIfmJ8TyYL1HRknH@6E2yhJKRAWWErkJP6lWcqlv5G4wl1Si668C4hBqLgNrld17IetkSkNLyliy97uJJpv@aw/dZ@C0rXJEr1ZwUUQJx4Y6jVj9FaN4GHpeHnxznaS@aFTNnZAQPDv7mRD1@HzB3JKLC1nyUzBD7uK9gfnW/2sB8hxmuXPrs7BxQiT/PFg7N7tt3sdA8GJa73JwWRl4PS9m2AzYkjmACfzt5vzF4TKzUaEUl2Vg4cw1G/wQ/76nlmO6y6aZw5lZvFnWBSV@fk2LeRlcsCwDh33Xy3IBSxCGytf55posXeXy4Ctk45jGXw "Python 2 – Try It Online") is a python script generating some test cases.
### The fact that I accepted an answer does not mean that the challenge is over; the winner can still change!

[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
Ó0ÛË
```
[Try it online!](https://tio.run/##DcexCYAwEAXQ/k8RrBXuX3KJNu6i4ApCwA0sLR0mxQ0Wfd0T23Ye/Tpr90f89bvXwVuY1uBtGDuhiEgwZBTMWECCETRoEREkyxb/C6hgQtEP "05AB1E – Try It Online")
**Explanation**
```
Ó     # get a list of prime exponents
 0Û   # remove leading zeroes
   Ë  # all remaining elements are equal
```
[Answer]
# Regex (ECMAScript), ~~276~~ ~~205~~ ~~201~~ ~~193~~ ~~189~~ ~~177~~ 174 bytes
Comparing the multiplicities (exponents) of different prime factors is an interesting problem for solving with ECMAScript regex – the lack of backreferences that persist through iterations of a loop makes it a challenge to count anything. Even if counting the numerical trait in question is possible, often a more indirect approach makes for better golf.
As with my other ECMA regex posts, I'll give a **spoiler warning:** I highly recommend learning how to solve unary mathematical problems in ECMAScript regex. It's been a fascinating journey for me, and I don't want to spoil it for anybody who might potentially want to try it themselves, especially those with an interest in number theory. [See this earlier post](https://codegolf.stackexchange.com/a/178889/17216) for a list of consecutively spoiler-tagged recommended problems to solve one by one.
So **do not read any further if you don't want some advanced unary regex magic spoiled for you**. If you do want to take a shot at figuring out this magic yourself, I highly recommend starting by solving some problems in ECMAScript regex as outlined in that post linked above.
The main payload from a regex I previously developed turned out to be very applicable to this challenge. That is the [regex that finds the prime(s) of highest multiplicity](https://gist.github.com/Davidebyzero/9735222#gistcomment-1197451). My first solution for that was very long, and I later golfed it way down in stages, first [rewriting it to use molecular lookahead](https://gist.github.com/Davidebyzero/9735222#gistcomment-1209588), and then [porting it back to plain ECMAScript](https://gist.github.com/Davidebyzero/9735222#gistcomment-1211502) using an advanced technique to [work around the lack of molecular lookahead](https://gist.github.com/Davidebyzero/9735222#gistcomment-1207638), and subsequently golfing it down to be much smaller than the original plain ECMAScript solution.
The part from that regex that applies to this problem is the first step, which finds Q, the smallest factor of N that shares all of its prime factors. Once we have this number, all we have to do to show that N is a "constant-exponent number" is divide N by Q until we can't any longer; if the result is 1, all primes are of equal multiplicity.
After submitting an answer using my previously developed algorithm for finding Q, I realized that it could be calculated in an entirely different way: Find the largest square-free factor of N (using the same algorithm as my [Carmichael number regex](https://codegolf.stackexchange.com/a/179024/17216)). As it turns out, this poses no difficulty at all in terms of stepping around the lack of molecular lookahead and variable-length lookbehind (no need to pull in the advanced technique previously used), and is 64 bytes shorter! [Note, at the time, molecular lookahead still offered a slight benefit, but thanks to later golfs, it no longer does at all.] Additionally it eliminates the complexity of treating square-free N and prime N as different special cases, dropping another 7 bytes from this solution.
(There still remain other problems that require the advanced technique formerly used here to golf down the calculation of Q, but currently none of them are represented by my PPCG posts.)
I put the multiplicity test before the consecutive-primes test because the latter is much slower; putting tests that can fail more quickly first makes the regex faster for uniformly distributed input. It's also better golf to put it first, because it uses more backreferences (which would cost more if they were double-digit). [The multiplicity test is now split in two for golf, with the consecutive-primes test sandwiched inside.]
I was able to drop 4 bytes from this regex (193 → 189) using a trick found by [Grimmy](https://codegolf.stackexchange.com/users/6484/grimmy) that can futher shorten the form of division in which the assertion that \$dividend-quotient\$ is divisible by \$divisor-1\$ can be skipped. (Skipping this assertion was already saving 4 bytes, so now it's saving 8 bytes.) This algorithm (in both its 4 byte longer form and the currently used one) is guaranteed to match the correct quotient when at least one of these constraints is met (along with satisfying the assertion that \$dividend\$ is divisible by \$divisor\$):
* \$divisor^2+2(divisor)+1 < 4(dividend)\$
* \$quotient=1\$  or equivalently  \$divisor=dividend\$
* \$divisor\$ is a prime power
	+ One of the cases in which this must be true is when \$dividend\$ is semi-prime and neither of the two other conditions are met. It also must be true if \$dividend\$ is a prime power.
We're actually not guaranteed in this context that any of those constraints will be met. Most notably, we're not even asserting that \$quotient\$ (which will become the next \$dividend\$) is still divisible by \$divisor\$ after each iteration of the loop. But an additional fact comes to the rescue: if the division algorithm matches an incorrect quotient (which it doesn't always do even when none of the above constraints are met), the incorrect answer is guaranteed to be less than \$divisor\$ but greater than \$1\$.
So if this happens when repeatedly dividing N by Q, the loop will terminate, and the final result will not be 1, thus guaranteeing no false positives. If N is actually a constant-exponent number, the correct quotient will always be greater than or equal to Q, so this doesn't cause any false negatives either.
Further golfs:
* -3 bytes by dividing by N just like any other largest square-free factor, instead of treating N being square-free as a special case ([inspired by H.PWiz](https://codegolf.stackexchange.com/questions/164911/is-this-a-consecutive-prime-constant-exponent-number/179412#comment441526_179412) but goes farther then what he did, saving 1 extra byte – he made it so the regex attempted to divide by 0 in the case that Q=N, and then asserted that the end result of the repeated division was Q rather than 1)
* -6 bytes by changing `(?=A)(?!B)` to `(?!B)A` (some of this is from multiple uses of backrefs changing from double to single digit, with less of the opposite occurring) – [thanks to H.PWiz](https://codegolf.stackexchange.com/questions/164911/is-this-a-consecutive-prime-constant-exponent-number/179412#comment441526_179412)
* -2 bytes by capturing the smallest prime as \$\ge 2\$ instead of augmenting the non-composite test to be a full prime test – [thanks to H.PWiz](https://codegolf.stackexchange.com/questions/164911/is-this-a-consecutive-prime-constant-exponent-number/179412#comment441526_179412)
* -2 bytes by removing an extraneous pair of parentheses – [thanks to H.PWiz](https://codegolf.stackexchange.com/questions/164911/is-this-a-consecutive-prime-constant-exponent-number/179412#comment441526_179412)
* -2 bytes by changing an outermost `(|(x+)\2*(?=\2$))` to `(|x*)\1*(?=\1\b)`, similarly to what I did [in the alternate answer here](https://codegolf.stackexchange.com/questions/144561/golf-the-pseudoprimes/179024#179024); one of these bytes is from a backref changing from double to single digit
And the regex:
`^(?=(|x*)\1*(?=\1\b)(((?=(xx+?)\4*$)(?=(x+)(\5+$))\6(?!\4*$))*x$))(?!(((xx+)(?=\9+$)(x+))(?!\8+$)(x+))\7*(?=\7$)(?!(\11\10?)?(xx+)\13+$))((?=((x*)(?=\2\16*$)x)(\15*$))\17)*x$`
[Try it online!](https://tio.run/##TU9LU8IwEP4rwDCw20ppkIdSQ08euHDQo9GZCKFEQ@gkQSqP345JZ5jxksn32m/3i/9wuzSydD1bypUw253@Fr9XQ7U4NF5E8VyVAEc660fXD8gpnKsIGYn8lxH2iQCBrKo4RzaM2lijGIGN4jYiG0PerHmMKv945ANVMPj8o7cEc6DZww2wST180q7djBBG0hzzOsXIfRhbd4JfJBgHjIx9QeU7ySg0MTIJbdeof8TE7V6dkboATKySSwHju94QMbM0zQ4bqQSAokbwlZJaAGKT6r1SeCqoSmyppINur4uZXANoWiRK6MJtcDY4n6Vd8AVIWnJjxVw7KN7Sd8SbIP4LekZyMg0yuo3ZHVpz/cOVXDUM14WYNlqxytY7A5l8oiKTcYy@sFW1EiNKwR1ITLbcLTdgEE@20yn9SQ7CFSQr98464y3Z5XJNe8M0/QM "JavaScript (SpiderMonkey) – Try It Online")
```
^                           # tail = N = input number
# Assert that all of N's prime factors are of equal multiplicity. There are two stages
# to this, which we will call Step 1 and Step 2. For golf reasons, a negative assertion
# is inserted between them.
# Step 1: Find Q, the largest square-free factor of N (which will also be the smallest
# factor of N that has all the same prime factors as N).
(?=
    (|x*)\1*(?=\1\b)        # cycle tail through all of the divisors of N, including N,
                            # from largest to smallest;
                            # \1 = the divisor, or zero if the divisor is N itself
    # Assert that tail is square-free (its prime factors all have single multiplicity)
    (                       # \2 = tail = the divisor
        (
            (?=(xx+?)\4*$)  # \4 = smallest prime factor of tail
            (?=(x+)(\5+$))  # \5 = tail / \4 (implicitly); \6 = tool to make tail = \5
            \6              # tail = \5
            (?!\4*$)        # Assert that tail is no longer divisible by \4, i.e. that
                            # that prime factor was of exactly single multiplicity.
        )*x$
    )
)
# Assert that there exists no trio of prime numbers such that N is divisible by the
# smallest and largest prime but not the middle prime.
(?!
    (                       # \7 = a factor of N
        (                   # \8 = a non-factor of N between \7 and \9
            (xx+)(?=\9+$)   # \9 = a factor of N smaller than \7 and greater than 1
            (x+)            # \10 = tool (with \11) to make tail = \9
        )
        (?!\8+$)
        (x+)                # \11 = tool to make tail = \8
    )
    \7*(?=\7$)              # tail = \7

    # Assert that \7, \8, and \9 are all prime
    (?!
        (\11\10?)?          # tail = either \7, \8, or \9
        (xx+)\13+$          # Assert tail is not composite; no need to test against
                            # 0 and 1, because we captured \9 > 1
    )
)
# Step 2: Require that the result of repeatedly dividing N by \2 is 1.
(
    # In this division calculation \15 = N / \2, we can skip the test for N-\15 being
    # divisible by \2-1. (Actually doing that test would make the regex 8 bytes larger.)
    # The quotient matched by this abbreviated algorithm is guaranteed to be correct if
    # the real quotient is 1 or is not less than the divisor, or if the divisor is a
    # prime power. Our input here is not guaranteed to satisfy any of those constraints.
    # But if none of those constraints are met, and the quotient matched by the algorithm
    # is incorrect, the incorrect quotient is guaranteed to be less than the divisor and
    # greater than 1. And once that happens, this loop will terminate, as the current
    # value will no longer be divisible by our divisor \2.
    (?=
        (                   # \15 = tail / \2
            (x*)            # \16 = \15-1
            (?=\2\16*$)
            x
        )
        (\15*$)             # \17 = tool to make tail = \15
    )
    \17                     # tail = \15
)*
x$                          # Require that the end result is 1
```
## Regex (ECMAScript+`(?*)`, ~~195~~ ~~187~~ ~~183~~ bytes
Obsoleted by no longer treating N being square-free as a special case (i.e. is now identical to the above).
## Regex (ECMAScript 2018), ~~198~~ ~~195~~ ~~194~~ ~~186~~ ~~182~~ bytes
Obsoleted by no longer treating N being square-free as a special case and changing `(?=A)(?!B)` to `(?!B)A` (i.e. is now identical to the above).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~13~~ ~~6~~ 5 bytes
```
ÆEt0E
```
[Try it online!](https://tio.run/##y0rNyan8//9wm2uJgev/h7u3hD1qWnO4HUj8/6@urm7EZcxlwmXKZcZlzmXBZcllaMhlaMxlaMplZG5gYMBlYmpmagzkG3AZGnEZmnCZA0kDCABqBgA "Jelly – Try It Online")
Still outgolfed... (thanks Erik for -1 byte)
---
**Explanation**
```
ÆE     # get a list of prime exponents (noooo long builtin name)
  t0   # remove zeroes on both sides (leading or trailing)
    E  # all remaining elements are equal
```
[Answer]
# JavaScript (ES6), 87 bytes
Returns **0** for truthy or a non-zero integer for falsy.
```
f=(n,k=2,j,i)=>n%k?j*(P=d=>k%--d?P(d):d==!i)(k)|j-i|(n>1&&f(n,k+1,j||i)):f(n/k,k,j,-~i)
```
[Try it online!](https://tio.run/##bdCxDoIwEAbgnbdwAHvaKkUBNSluzgxuxoFQ0bakGFETE@Kro8RFPbr1y93lz6@ze1bnF3W@MlvJQ9sWglhqREA1VSAS65q1HpFUSJEYlzG5TomElRRioIAYaDRTDbEJ97yiWxxzqptGAaze36mh5n2HPRW0eWXrqjxMyupIhrvt5XY9PfZDcL69IAH8ywzJHEmIJEISI1kgWSLhHBNOxHGAIPZ9H0cPo3DW7Tu/dWyysu5pg@MLHDfEcSFxz5T/eQDtCw "JavaScript (Node.js) – Try It Online")
### Commented
```
f = (                     // f() = recursive function taking:
  n,                      //   n = input
  k = 2,                  //   k = current factor
  j,                      //   j = reference exponent, initially undefined
  i                       //   i = current exponent, undefined each time we start testing
) =>                      //       the next factor
  n % k ?                 // if k is not a divisor of n:
    j * (                 //   ignore the primality of k if j is still undefined
      P = d =>            //     P() = function testing if k is prime:
        k % --d ?         //       decrement d; if d is not a divisor of k:
          P(d)            //         do a recursive call until it is
        :                 //       else:
          d == !i         //         unless i is already defined: d must not be equal to 1
                          //         (if it is: k is the next prime but does not divide n)
    )(k) |                //   initial call to P() with d = k
    j - i | (             //   if both i and j are defined, they must be equal
      n > 1 &&            //   if n is not yet equal to 1,
      f(n, k + 1, j || i) //   go on with k + 1; if j is undefined, set it to i
    )                     //   (otherwise, stop recursion and return what we have)
  :                       // else:
    f(n / k, k, j, -~i)   //   increment the current exponent and go on with n / k
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~30~~ 29 bytes
```
{mFz~)-!\__W=,\0=>\-:mp1#W=&}
```
[Try it online!](https://tio.run/##S85KzP3/vzrXrapOU1cxJj4@3FYnxsDWLkbXKrfAUDncVq32f2Gdqp/W/2gjLmMuEy5TLjMucy4LLksuQ0MuQ2MuQ1MuI3MDAwMuE1MzU2Mg34DL0IjL0ITLHEgaQEAsAA "CJam – Try It Online")
My first answer after a nearly 2(!)-year break, so it can probably be golfed more. This is a block that takes input as an integer (can also be mapped over for arrays of integers).
## Explanation
```
{        e# Begin block
 mF      e# Factor input, giving an array of primes and their powers
 z~      e# Transpose and dump, giving an array of primes and an array of powers
 )-      e# Check that the powers are the same: subtract each power from the last element
 !       e# Negate to make sure they're all 0
 \__W=,  e# Get the range from 0 to the largest prime minus one
 \0=>    e# Slice that array so it only includes everything larger than the smallest prime
 \-      e# Remove the original primes from the range array
 :mp     e# Check each element for primality. If the input's primes are consecutive,
         e# this will contain no primes
 1#W=    e# Make sure a "1" is not found
 &       e# If the powers are the same AND primes are consecutive, return 1. Otherwise, 0.
}
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~5~~ 6 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
╣♥qJ╬c
```
[Run and debug it](https://staxlang.xyz/#p=b903714ace63&i=2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A11%0A13%0A15%0A512%0A27000%0A456533%0A10%0A12%0A14%0A72%0A10000000&a=1&m=2)
Unpacked, ungolfed, and commented, it looks like this.
```
|n    get the exponents of the prime factorization
0:D   trim leading zeroes
:u    array has exactly a single distinct element
```
**Edit:** ~~This doesn't work on `512`. I'll give it some thought and hopefully a fix later.~~ It works now.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 9 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
1 is truthy, 0 is falsy
```
αAG<└\{┬⌠
```
[Run and debug it](http://stax.tomtheisen.com/#p=e041473cc05c7bc2f4&i=2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A11%0A13%0A15%0A27000%0A456533%0A%0A10%0A12%0A14%0A72%0A10000000%0A%0A108%0A2250&m=2)
**Explanation**
```
|nX0-u%x:^=      # Full Program, unpacked, implicit input
|n               # Exponents of sequential primes in factorization. (eg. 20 -> [2 0 1])
  X              # Save to X register
   0-            # Remove all '0' from array
     u%          # Get unique numbers and get length of array
       x         # Copy back the array saved to X
        :^       # Is it ascending
         =       # Are the two comparisons equal? implicit output
```
Can probably be golfed more, but it covers the cases I was missing in the last solution.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 11 bytes
```
Λ§*≈¤≈oṗ←gp
```
[Try it online!](https://tio.run/##yygtzv6fq@GlpKBrp6AUnKpR/KipsUhT89C2/@dmH1qu9aiz49ASIJH/cOf0R20T0gv@//9vxGXMZcJlymXGZc5lwWXJZWjIZWjMZWjKZWRuYGDAZWJqZmoM5BtwGRpxGZpwmQNJAwgAAA "Husk – Try It Online")
Outputs 0 if not a consecutive-prime/constant-exponent number.
[Answer]
# Java 10, ~~223~~ ~~191~~ ~~178~~ ~~176~~ 168 bytes
```
n->{var s=new java.util.HashSet();for(int f=1,i=1,x,j;n>1;){for(x=++i,j=2;j<x;)x=x%j++<1?1:x;if(x>1){for(j=0;n%i<1&&n>(f=0);n/=i)j++;if(f<1)s.add(j);}}return s.size();}
```
Returns `1` as truthy, and `>=2` as falsey.
[Try it online.](https://tio.run/##bVJdT8MgFH33V9w0cYGwdWWfOsp8M764l/mmPuBGFeyYKXRWl/72ST@WrIkECOfey8m5B7Q4iIHefp42qbAWHoUyxysAZZzMErGRsKpgHYANqnaDmY@UfvlpnXBqAyswwOFkBsvjQWRguZHfoD11mDuVhg/CfqylQ5gl@6wmSTjtK7@KvmZmSRk@VpmCE6L6mo@YjguGC15ca0JiekcXBVMJKpa0KdQ8YuZaxbTXM0uU8AgzM@QK@@qqLokptqHYbpHGrCwz6fLMgA2t@pVeRHlijfqv/C316tsmDnu1hZ03AK1dpsz78ysI3HQ/HMJTlruPn0UNz10orxRUzG/9TgiucwBOWodU7VILKO2gcQdNL9FoHkXRZWAynU3H5wvrH@vkLtznLvzyCl1qUJs5q7wXqZWtyoa@w0ZHHTS5RPNu7nY0v@kEomb88/q1cU3XlSmtZ/@IVSRYvLiAIP9ycnYX@PMiCDAxof9auGUuT38)
**Explanation:**
```
n->{                   // Method with integer parameter and boolean return-type
  var s=new java.util.HashSet();
                       //  Set to keep track of the prime exponents
  for(int f=1,         //  Prime-flag, starting at 1
          i=1,x,j;     //  Index and temp integers
          n>1;){       //  Loop as long as `n` is still larger than 1
    for(x=++i,         //   Set `x` to `i`, after we've increased `i` by 1 first with `++i`
        j=2;           //   Set `j` to 2 (first prime)
        j<x;)          //   Inner loop as long as `j` is still smaller than `x`
      x=x%j++<1?       //    If `x` is divisible by `j`:
         1             //     Set `x` to 1
        :              //    Else:
         x;            //     Leave `x` unchanged
    if(x>1){           //    If `x` is larger than 1 (if `i` is a prime):
      for(j=0;         //     Use `j` as counter, and set it to 0
          n%i<1        //     If `n` is divisible by `i`:
                       //      And loop as long as `n` is still divisible by `i`,
          &&n>         //      and `n` is larger than 0
              (f=0);   //      (and set `f` to 0 at the same time)
          n/=i)        //       Divide `n` by `i`
        j++;           //       And increase `j` by 1
      if(f<1)          //     If the flag `f` is now/still 0:
        s.add(j);}}    //      Add counter `j` to the Set
  return s.size();}    //  Return the amount of items in the Set
                       //  (1 being true, >=2 being false)
```
**Some example inputs:**
`n=15`:
* Flag remains `1` for the first prime 2 (because 15 is not divisible by 2).
* Flag goes from `1` to `0` as soon as we're at the prime 3. Since 15 is divisible by 3, `n` becomes 5 (15/31), and the Set becomes `[] → [1]`.
* Then we check the next prime 5. Since 5 is divisible by 5, `n` becomes 1 (5/51), and the Set remains the same (`[1] → [1]`).
* Now `n=1`, so we stop the outer loop. The Set (`[1]`) only contains one item, the `1` from both adjacent primes 3 and 5, so we return true.
`n=14`:
* Flag goes from `1` to `0` for the first prime 2 (because 14 is divisible by 2). `n` becomes 7 (14/21), and the Set becomes `[] → [1]`.
* Then we check the next prime 3. Since 7 is not divisible by 3, `n` remains the same, and the Set becomes `[1] → [1,0]`.
* Then we check the next prime 5. Since 7 is also not divisible by 5, `n` remains the same, and the Set remains the same as well (`[1,0] → [1,0]`).
* Then we check the next prime 7. Since 7 is divisible by 7, `n` becomes 1 (7/71), and the Set remains the same (`[1,0] → [1,0]`).
* Now `n=1`, so we stop the outer loop. The Set (`[1,0]`) contains two items, the `1` from the non-adjacent primes 2 and 7, and the `0` from the primes 3 and 5, so we return false.
`n=72`:
* Flag goes from `1` to `0` for the first prime 2, because 72 is divisible by 2 (multiple times). So `n` becomes 9 (72/23), and the Set becomes `[] → [3]`.
* Then we check the next prime 3. Since 9 is divisible by 3 (multiple times), `n` becomes 1 (9/32), and the Set becomes `[3] → [3,2]`.
* Now `n=1`, so we stop the outer loop. The Set (`[3,2]`) contains two items, the `3` from prime 2, and the `2` from prime 3, so we return false.
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~12 11~~ 10 bytes
```
YFtgYsg)Zs
```
[Try it at MATL Online!](https://matl.io/?code=YFtgYsg%29Zs&inputs=27000&version=20.9.1)
Thanks to Luis Mendo for the remove-leading-zeroes part. He also pointed out that swapping truth values is allowed, so this returns **0** for numbers that satisfy the challenge requirements and any positive value otherwise.
Grosso Modo, this generates the exponents of the sequential prime factorization, removes leading zeroes and calculates the standard deviation.
[Answer]
# [J](http://jsoftware.com/), 16 bytes
Big thanks to FrownyFrog for -8 bytes!
```
(=&#+/\=@#])_&q:
```
[Try it online!](https://tio.run/##Rc7BCsIwDAbge58ibLBuzNZkM6sWCj6IYwexDC8iO@/Z60ETc/oIP3/yLHlLHhAiYGlTU/fHW7rWc7c071g6U3mwOXkLB9gj5M2Yx319QYZBMApOAhZMgiA4Cy4CIpU2kTYMARH1AE88/kLWOWc1rxHSt0jfCf8dfkfbmcsH "J – Try It Online")
## My old solution:
# [J](http://jsoftware.com/), 24 bytes
```
[:(1=[:#@~.{.@I.}.])_&q:
```
[Try it online!](https://tio.run/##Rc7BCsIwDAbge58iKFgHNiSbXTVQ2NVnGOJBLMOLyI4yX70eNDGnj/DzJ/da5oxAIEB1lC3nUdbDG184nHDBc3PZPKU2boXgS0YPO1gEyuzc7To9oECr6BR7RVT0iqQ4KI4KZpM1sTW0iYjsQOxj9wv5EIK3vEXY3mJ7J/139J36AQ "J – Try It Online")
## Explanation:
`_&q:` prime exponents
`{.@I.}.]` removes the leading zeros by finding the first non-zero element:
```
     }.   drop
       ]  from the list of exponents
{.@       as much items as the first of the
   I.     indices of non-zero elements
```
`1=[:#@~.` tests if all remaining numbers are equal:
```
  [:#@~.  finds the length of the list after removing the duplicates
1=        is it 1?
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
0iYFhdz
```
The result is `1` iff input satisfies the requirement.
[Try it online!](https://tio.run/##y00syfn/3yAz0i0jper/fyNzAwMDAA) Or [verify all test cases](https://tio.run/##JccxCoAwDEDR/Z8maZpWd/EELm4VHBR0c/LyseAfHvx7e65oIec6H/sb0xIJI@MUKgMjqqihTqoiQvbi1l/QhGZqV/4@)
### Explanation
```
0    % Push 0
i    % Push input number
YF   % Exponents of consecutive prime factors
h    % Concatenate horizontally
d    % Consecutive differences
z    % Number of nonzeros. Implicitly display
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 67 bytes
```
@(x)~any(diff(find(h=histc(factor(x),primes(x))))-1)&h(h>0)==max(h)
```
[Try it online!](https://tio.run/##TYzhCoIwAIT/31P4Kzcw2dRpEYteZahjA52hM5SoV7eRBN2P4@C7u6H26tFuWqZput3IQt/KraSxWhNtXUOMNHbyNdGq9sMYeHIfbd9OIQUdOT0YYq6MStmrhRi6@XH2Zo1k9MyQo4BAiQonnME5eA4ukFWMMRSiFHn@ukCrbmq/C87AM/ACVXC2KxRQt12nZ0d0sr8n8ezihNE/sJ/8wPYB "Octave – Try It Online")
I believe this is the only solution that uses a histogram.
### Explanation:
This makes a histogram, where the variable to be counted are the factors of the input, and placed in the bins `primes(x)`, which is all primes less than the input. We then find the location of the prime factors, takes the difference between each of the indices and subtract one. If there are any elements that aren't zero (i.e. the difference of the indices of prime numbers is not 1), then this will result in a falsy value, otherwise it will return a truthy value.
We then chech that all non-zero elements in the histogram are equal to the maximum element. If there are values that aren't equal then this will result in a falsy value, otherwise it will return a truthy value.
If both those blocks are truthy then our input is a consecutive prime constant exponent number!
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 28 bytes
```
{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/Py3vUduE6jSFAiCV8Kht8qPetY96tz7qbtEwtH3UuehRx6oCzUcdyx91rNBPe9S7/VHvDkOwks1AVbX//6uHFJWWZFRaqXOl5SkYgQhjEGECIkxBhBmIMAcRFiDCEkQYGoJJsEpDsCojcwMDA7BGUzNTY2MuQ9NHvVvUddW51N0Sc4qhxhuCVRiCbTEE22AOYRuAND/qnatQkpmbWqyQX1qiABMGAgA "APL (Dyalog Extended) – Try It Online")
### How:
```
{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵} ⍝ Monadic function, takes an argument ⍵
       ⍭⍵                     ⍝ Prime factors and exponents of ⍵
     `↓                        ⍝ split the resulting matrix in 2 vectors
 f p←                          ⍝ assign the factors to f and the powers to p
         ⋄                     ⍝ then
                          ⍳⍵   ⍝ range [1..⍵]
                        1⍭     ⍝ primality check for each element in the vector
                       ⍸        ⍝ where; returns the indices of truthy values
                     f⍷         ⍝ find the factors; returns a boolean vector
                   ∨/           ⍝ logical OR reduction
                  ∧             ⍝ logical AND
           (   ∪p)              ⍝ unique members of the powers
              ≢                 ⍝ tally; returns the number of elements in the vector
            1=                  ⍝ check if there's only one element
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 65 bytes
```
Differences[{PrimePi@#,#2}&@@@FactorInteger@#]~MatchQ~{{1,0}...}&
```
[Try it online!](https://tio.run/##JYuxCoMwEIZf5SDgdLWJVm2Hlgyl0KFgZ3EIIdEMWkizhfjq6Ul/OP7ju/sWFWazqOC0yhau@e6sNd6s2nyH2Hu3mN5JhqxKhZTyoXT4@OcazGS8ZOP2UkHP7y1GgTyVZZmKTNIaBgaHG9iBjSMUcJQQK4Qa4YTQILQIHcIZ4YIgBA1dBPGq45zTU9M29Y5oF@QJsrq9@T8p/wA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 63 bytes
```
n->#Set(vector(#(a=factor(n)~),i,[primepi(a[1,i])-i,a[2,i]]))<2
```
[Try it online!](https://tio.run/##JYzRCsIwDEV/5bK9NJBCu7lNwe0nfBx9KLJJQWsZRfDFX6@ZBkJObu5N8lvQt1RWjCXqqb4sWb2Wa35uqlZ@XP0PI32IA89pC48lBeVny8GRDuznRsgRnZviU7q/VYSeIMaYBat9qbDKB2KIFy3jwOgYPWNgHBknhrXScrGiN4MxRkxd37W7JGwlZyU17NP8y1H5Ag "Pari/GP – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 14 bytes
```
1#.2~:/\0,_&q:
```
1 in the output indicates consecutive constant exponent.
[Try it online!](https://tio.run/##Rc7BCsIwDAbge58iOLAIa5d0ZnWFvYngQSziRWRnffV6cPnN6SP8/Mmj1XWJxFSIm3Qxfcpw5v6yf5V2cLtIvi7RU0/vQnV17na9P6lSMoyGo0ENkyEbTobZIAKhSdCQMjPjgE46biEfQvDIIyJ4S/BO/u/4N2hXbV8 "J – Try It Online")
```
        0,_&q:   zero followed by the prime exponents of input
   2~:/\         for every two consecutive values, 1 if they are different
1#.              convert from base-1, just add them up
```
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 127 bytes
```
import StdEnv
@n=[]== $n
?n#j= $n
= @n||j==filter@[hd j..last j]&&any(\p=(prod j)^p==n)[1..n]
$n=[i\\i<-[2..n-1]|n/i*i==n&& @i]
```
[Try it online!](https://tio.run/##PY5PC4JAFMTvfooHhVSgYdCtRx7qEHTzqBts/qknu09Z10Dws7ctBd3mNzMMU6pastNdNaoatCR2pPvOWMhsdeZXkDLmAhGWHBx50X4FQsrz3CI2pGxt0vxZQRvHSg4WWhGGkqdV0eOqN50P1rcekdd5EscsgqXfo6KgQ5TvvBElYuYtbchXwhBSEi6z0thgATzqe20AYZ/sPDYjl5Y69sbRP/jjr@beZaPkY3DR5epOE0tN5fAB "Clean – Try It Online")
Defines the function `? :: Int -> Bool` using `$ :: Int -> [Int]` to factorize and `@ :: Int -> Bool` to check primality.
[Answer]
# APL(NARS) 41 chars, 82 bytes
```
{(1=≢∪+/¨{v=⍵⊃v}¨⍳≢v)∧(1↓w)≡¯1↓1πw←∪v←π⍵}
```
{π⍵} is the function factorization of argument ⍵ in the list of prime factors (repeat if one prime appear more time);
{1π⍵} is the function next prime (note that in this case its argument is not a scalar but one array of integers). test:
```
  h←{(1=≢∪+/¨{v=⍵⊃v}¨⍳≢v)∧(1↓w)≡¯1↓1πw←∪v←π⍵}
  (2..30)/⍨h¨2..30
2 3 4 5 6 7 8 9 11 13 15 16 17 19 23 25 27 29 30
  h¨27000 456533 72 10000000
1 1 0 0
```
]


[Question]
      [
### Challenge:
Given a positive integer input **n**, create a vector that follows this pattern:
```
0  1  0 -1 -2 -1  0  1  2  3  2  1  0 -1 -2 -3 -4 -3 -2 -1 ... ±(n-1) ±n
```
Or, explained with words: The vector starts at `0`, and makes increments of `1` until it reaches the smallest odd positive integer that isn't part of the sequence, then it makes decrements until it reaches the smallest (in magnitude) even negative integer that isn't part of the sequence. It continues this way until `n` is reached. The sequence will end on positive `n` if `n` is odd, and negative `n` if `n` is even.
The output format is flexible.
### Test cases:
```
n = 1
0  1
-----------
n = 2
0  1  0 -1 -2
-----------
n = 3
0  1  0 -1 -2 -1  0  1  2  3
-----------
n = 4
0  1  0 -1 -2 -1  0  1  2  3  2  1  0 -1 -2 -3 -4
-----------
n = 5
0  1  0 -1 -2 -1  0  1  2  3  2  1  0 -1 -2 -3 -4 -3 -2 -1  0  1  2  3  4  5
```
You may choose to take the **n** zero-indexed. `n = 1` would then give `0 1 0 -1 -2`.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in each language wins! Explanations are encouraged as always!

[Answer]
# [R](https://www.r-project.org/), ~~58~~ ~~54~~ ~~50~~ ~~48~~ 43 bytes
*-2 bytes thanks to MickyT*
```
function(n)diffinv(rep(1:n%%2*2-1,1:n*2-1))
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/TyNPMyUzLS0zr0yjKLVAw9AqT1XVSMtI11AHyATRmpr/0zRMNf8DAA "R – Try It Online")
```
function(n)
 diffinv(                           # take cumulative sum, starting at 0 of
             1:n%%2*2-1,            # a vector of alternating 1,-1
         rep(                       # repeated
                        1:n*2-1))   # 1, 3, 5, etc. times
```
[Answer]
# [Perl 6](https://perl6.org), ~~60~~ 26 bytes
```
{flat {((1,-*...*)ZX*(-$++...0...$++)xx$_)}(),$_*($_%2||-1)}
```
[Try it](https://tio.run/##FY3BCoJAFEX3fsVdjM1748wjhdyEfkdEIGK6Sg21UNRvn2xx4JzVedfDK/WfscY3leoatAtOVf@skfm1eZUTVqLYOiMihu83Q05F0RHng8N4nlXBO7FVhSFVhMm2uZh33/QDYpELXI5HhzUAxnJBJ007kQ6TUbOFRpZDW/yH1HGw@x8 "Perl 6 – Try It Online")
```
{[...] (-1,-*...*)Z*0..$_}
```
[Try it](https://tio.run/##Fcy7DoIwAAXQvV9xB6GPtDdiIouBDxGJMVgmKYaKCSF8e8XtTOftp1eZ5ujxLdldxLAg78anR5XWhmQL5QrrzE6jr@ZIHu5b6scJBXmGq3ELWAUQHwsC@@GjZHaKUltIVDWkxb9TQYst/QA "Perl 6 – Try It Online")
## Expanded:
```
{  # bare block lambda with implicit parameter $_
  [...]  # reduce using &infix:«...» (sequence generator)
          ( -1, -* ... * ) # (-1, 1, -1, 1 ... *)
      Z*                   # zip multiplied with
          0 .. $_          # range up to and including input
}
```
`(-1,-*...*)Z*0..$_` generates the sequence `0 1 -2 3 -4 5`
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~9~~ 7 bytes
*Saved 2 bytes thanks to @Emigna*
```
Ýā®sm*Ÿ
```
[Try it online!](https://tio.run/##MzBNTDJM/f//8NwjjYfWFedqHd3x/78pAA "05AB1E – Try It Online")
My first 05AB1E answer (I think), so I may be missing some tricks...
### Explanation
```
Ý         # push range [0 ... n]   stack: [[0 ... n]]
 ā        # push range [1 ... len(prev)]  [[0 ... n], [1 ... n+1]]
  ®       # push value of register        [[0 ... n], [1 ... n+1], -1]
   s      # swap top two values           [[0 ... n], -1, [1 ... n+1]]
    m     # power                         [[0 ... n], [-1, 1, -1, 1, ...]]
     *    # multiply                      [[0, 1, -2, 3, -4, 5, ...]]
      Ÿ   # range interpolation           [[0, 1, 0, -1, -2, -1, ...]]
```
I have to thank @Dennis for [the original usage of `Ÿ`](https://codegolf.stackexchange.com/a/74860/42545), otherwise I ~~may not~~ probably would never have known about it...
[Answer]
# [Python 2](https://docs.python.org/2/), ~~69~~ ~~57~~ 56 bytes
```
f=lambda n:[0][n:]or f(n-1)+range(-n,n+1)[::n%2*2-1][2:]
```
[Try it online!](https://tio.run/##JcoxDoQgEAXQq0yzERQSodhijCdBCswuu5Po1xAbT48mVq95@3n8N/ha87ikdf4kAoc@BnDcCmUF63RXEn5fZWHQOR2Y8fKtty4Gz7Hm@wkJ6FnOvDXvRXCQDI9ZiTbNhKZe "Python 2 – Try It Online")
For each `n` up to the `input` the `range(-n,n)` (inclusive) is calculated, inverted when `n` is an even number, has the fist two numbers (after the inversion) removed, and then appended to the output.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~15~~ 14 bytes
```
ÝDÉ·<*Ý€û˜ÔsF¨
```
[Try it online!](https://tio.run/##ASUA2v8wNWFiMWX//8OdRMOJwrc8KsOd4oKsw7vLnMOUc0bCqP/Dr/81 "05AB1E – Try It Online")
**Explanation**
```
Ý                # push range [0 ... n]
 D               # duplicate
  É·<            # (x % 2 == 1)*2-1 for each
     *           # multiply
      Ý          # range [0 ... a] for each
       €û        # palendromize each
         ˜       # flatten
          Ô      # connected uniqueified
           sF¨   # remove the last n elements
```
[Answer]
# JavaScript (ES6), 56 bytes
```
f=(n,b=d=1,k=0)=>[k,...k-d*n?f(n,k-b?b:(d=-d)-b,k+d):[]]
```
[Try it online!](https://tio.run/##Dcw9DoMwDEDhnVN4I25@VIYuFJeDIAaCSQVBTgVVl6pnTzO94ZPeNn2mcz7W19tK4iXnQEqMJ6bGRLoiPYZonHPR8kX6UCxa3/tWMVlG603UjO0wjjmkQwkQNHcQ6AhupVojfCuAOcmZ9sXt6anKA92WVlG1gRqx@uU/ "JavaScript (Node.js) – Try It Online")
### Commented
```
f = (               // f = recursive function taking:
  n,                //   n = input
  b =               //   b = boundary value, initialized to 1
  d = 1,            //   d = current direction, initialized to 1
  k = 0             //   k = current sequence value, initialized to 0
) =>                //
  [                 // update the sequence:
    k,              //   append the current value
    ...k - d * n ?  //   if |k| is not equal to |n|:
      f(            //     append the (spread) result of a recursive call:
        n,          //       use the original input
        k - b ?     //       if k has not reached the boundary value:
          b         //         leave b unchanged
        :           //       else:
          (d = -d)  //         reverse the direction
          - b,      //         and use a boundary of higher amplitude and opposite sign
        k + d       //       update k
      )             //     end of recursive call
    :               //   else:
      []            //     stop recursion and append nothing
  ]                 // end of sequence update
```
[Answer]
# [Haskell](https://www.haskell.org/), 43 bytes
```
f n=scanl(-)0[(-1)^k|k<-[1..n],_<-[2..2*k]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz7Y4OTEvR0NX0yBaQ9dQMy67JttGN9pQTy8vViceyDLS0zPSyo6N/Z@bmJmnYKtQUJSZV6KgkaZgovkfAA "Haskell – Try It Online")
Computes the negated cumulative sums of the list `[(-1)^k|k<-[1..n],_<-[2..2*k]]`, which is the first `n` rows of
```
[-1,
 +1, +1, +1,
 -1, -1, -1, -1, -1,
 +1, +1, +1, +1, +1, +1, +1…
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~11~~ 9 bytes
```
²ḶÆ½-*0;Ä
```
[Try it online!](https://tio.run/##ASwA0/9qZWxsef//wrLhuLbDhsK9LSowO8OE/8OH4oKsR///MSwgMiwgMywgNCwgNQ "Jelly – Try It Online")
### How it works
```
²ḶÆ½-*0;Ä  Main link. Argument: n
²          Square; yield n².
 Ḷ         Unlength; yield [0, ..., n²-1].
  Æ½       Take the integer square root of each k in the range.
    -*     Compute (-1)**r for each integer square root r.
      0;   Prepend a zero.
        Ä  Accumulate; take the sums of all prefixes.
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~48~~ 42 bytes
```
f n=0:[(-1)^i*x|i<-[0..n-1],x<-[1-i..i+1]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz9bAKlpD11AzLlOroibTRjfaQE8vT9cwVqcCyDbUzdTTy9Q2jI39n5uYmadgq1BQlJlXoqCikKZg8h8A "Haskell – Try It Online")
*Thanks to [Οurous](https://codegolf.stackexchange.com/users/18730/%ce%9furous) for -1 byte*
Even though it's kind of obvious in hindsight, it took me a while to arrive at `(-1)^i*x` which is `x` when `i` is even and `-x` when `i` is odd. Previous iterations where:
```
(-1)^i*x
x-2*mod i 2*x
(-1)^mod i 2*x
[x,-x]!!mod i 2
(1-sum[2|odd i])*x
```
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), ~~300~~ 167 bytes
I've never done any of these before, but this one seemed fun. I see why people use those "golfing" languages as 167 seems way higher than some of the other answers. But, you gotta go with what you know.
```
static int[] f(int n){if (n==1) return new int[]{0,1};var a=f(n-1);return a.Concat(a.Skip(a.Length-(n-1)*2).Select(x=>-x)).Concat(new int[]{(n%2)!=0?n:-n}).ToArray();}
```
[Try it online!](https://tio.run/##TY9BS8NAEIXv@RVjQdiRZkmKJ5dUxJtUKETwUHoY1k26mM7q7ra2hPz2uMSKDgzDwPce7@mQa@fNeAiWW6jPIZq9yv5/cmX5U2W6oxBg7V3raZ/1Y4gUrQbLcbOFRqQLjL1tQHBVlQjexINnYPP1w/TFvBzUkTxQ1QjOS1QXhOSjY01RkKzf7Uc6K8Nt3OUTdbNAWZvO6ChO1TI/If7if9aCrxd4VRX3fJfzgPLFPXhPZ4FqGAEuSY/OvsEzWRYh@lQvxSbMAPq0AMkzuM7IV2@jSY2NqCdKPrmkmMFsPnWUa/LBCNoUW0yjknbIhnG8/QY "C# (.NET Core) – Try It Online")
```
// Recursive Worker Function
static public int[] f( int n )
{
    // Start with the simple case
    if ( n == 1 ) return new int[]{0,1};
    // Recusively build off of that
    var a = f(n-1);
    // To be added at the end
    int[] b = { (n%2) !=0 ? n : -n };
    // Skip some based on length
    int s = a.Length - (n-1)*2;
    // With the rest, multiply by -1 and then append to the end
    // And append the part
    return a.Concat( a.Skip(s).Select( x => -x ) ).Concat( b ).ToArray();
}
```
[Answer]
# [J](http://jsoftware.com/), 25 bytes
-5 bytes thanks to FrownyFrog!
```
>:@*:$i.;@(<@i:@*_1&^)@,]
```
[Try it online!](https://tio.run/##y/qfVmyrp2CgYKVg8N/OykHLSiVTz9pBw8YhE8iJN1SL03TQif2vyaWkp6CeZqunrqCjUGulkFbMxZWanJGvoKOXpqCmZ6dgqJ2pZ8b1HwA "J – Try It Online")
# [J](http://jsoftware.com/), 30 bytes
```
>:@*:{.;@([:(i:@*_1&^)&.>i.,])
```
Explanation:
`i.,]` creates list 0..n
`&.>` for each number in the list execute the verb in (...) and box the result (I need boxing because the results have different length)
`[:( _1&^)` find -1 to the `i`th power (-1 or 1)
`i:@*` make a list -n..n or n..-n, depending on the sign of the above
`;@` unbox
`>:@*:` find n^2 + 1
`}.` and take so many numbers from the list
[Try it online!](https://tio.run/##y/qfVmyrp2CgYKVg8N/OykHLqlrP2kEj2kojE8iJN1SL01TTs8vU04nV/K/JpaSnoJ5mq6euoKNQa6WQVszFlZqcka@go5emAFSlYKidqWfG9R8A "J – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~65~~ 56 bytes
```
r=k=0;exec'print r;r+=1-k**.5//1%2*2;k+=1;'*-~input()**2
```
The output format is a bit ugly. **:/**
[Try it online!](https://tio.run/##HY3BCsIwEETP2a/IRaIrtSbaiyHHevXiD2hZaIikYUnRXvz1mHoZmIH3Ji15nKIp79G/SN55pguIzEtNQR8apFKqsAvuaNeqEvuYJVveO90ExEPXtnpj0NhQF6uw@fqY5rzdIZoiRMWr6U8BVONAKcv@du2ZJ15PnkyPUDQYOMEZuh8 "Python 2 – Try It Online")
[Answer]
# Java 8, ~~85~~ ~~83~~ 79 bytes
```
n->{for(int p=0,i=0;i<=n*n;p+=1-(int)Math.sqrt(i++)%2*2)System.out.println(p);}
```
-6 bytes thanks to *@OlivierGrégoire*.
[Try it online.](https://tio.run/##LY7LDoIwEEX3fsVsTFoQgiSuav0D2LA0LmoBLcJQaSExhG/H8khmFnPnJPdUYhBBlX9mWQtjIBEKxwOAQlt0pZAFpMsJMLQqB0lcDkiZiya3bowVVklIAYHDjMFtLNtuxTSPTopHTF05esi0z8/B8qCJsO/QfDtLlO/TY@zFNPsZWzRh29tQd46pkWjKppltJbp/1q5k71pVGidKMuvg1/0h6CaJoSSX3W6a/w)
**Explanation:**
```
n->{                            // Method with integer parameter and no return-type
  for(int p=0,                  //  Set both `p` to 0
      i=0;i<=n*n;               //  Loop `i` in the range [0, `n*n`]
      p+=                       //    After every iteration, increase `p` by:
         1-                     //     1, minus:
           (int)Math.sqrt(i++)  //     The square-root of `i`, truncated to its integer
           %2*2)                //     Modulo 2, and multiplied by 2
     System.out.println(p);}    //   Print integer `p` with a trailing new-line
```
[Answer]
# [R](https://www.r-project.org/), ~~48 46~~ 42 bytes
```
for(i in 1:scan())F=c(F,-(-1)^i*(2-i):i);F
```
[Try it online!](https://tio.run/##K/r/Py2/SCNTITNPwdCqODkxT0NT0802WcNNR1dD11AzLlNLw0g3U9MqU9Pa7b/ZfwA "R – Try It Online")
A port of [the Ruby answer](https://codegolf.stackexchange.com/a/165068/80010) by Kirill L. - and saved 6 bytes thanks to the same Kirill L.! Now shorter than [Giuseppe's solution](https://codegolf.stackexchange.com/a/165068/80010) ;)
A port of [this Octave answer](https://codegolf.stackexchange.com/a/165005/80010) by Luis Mendo using `approx` is less golfy. `n=n^2+1` can be replaced by `,,n^2+1`; or by `0:n^2+1`(positional argument `xout`) for the same byte count :
### [R](https://www.r-project.org/), 56 bytes
```
f=function(n)approx((0:n)^2+1,-(-1)^(0:n)*0:n,n=n^2+1)$y
```
[Try it online!](https://tio.run/##K/r/P802rTQvuSQzP08jTzOxoKAov0JDw8AqTzPOSNtQR1dD11AzDszXAhI6ebZ5IHFNlcr/xUDFOZUahlZmOnATKjSTE0s00oC0jhKXkqbmfwA "R – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 17 bytes
```
+\0,¯1*⍳(/⍨)1+2×⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OApHaMgc6h9YZaj3o3a@g/6l2haahtdHg6kPf/f5qCCQA "APL (Dyalog Unicode) – Try It Online")
Golfed 2 bytes thanks to @FrownyFrog by converting to a train. See the older answer and its explanation below.
---
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 19 bytes
```
+\0,∊⊢∘-\⍴∘1¨1+2×⍳⎕
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkGXI862tP@a8cY6Dzq6HrUtehRxwzdmEe9W4C04aEVhtpGh6c/6t0MVP4fqPB/GpcJAA "APL (Dyalog Unicode) – Try It Online")
(Uses `⎕IO←0`)
My first approach was to construct multiple ranges and concatenate them together, this easily went over 30 bytes. Then I started analysing the sequence
```
      +\⍣¯1⊢0  1  0 ¯1 ¯2 ¯1  0  1  2  3  2  1  0 ¯1 ¯2 ¯3 ¯4
0 1 ¯1 ¯1 ¯1 1 1 1 1 1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1
```
`+\⍣¯1` denotes the inverse cumulative sum
There is a repeating pattern of 1s and ¯1s, where the length of each consecutive sequence of 1s or ¯1s is 1+2×n. And each subsequence alternates between 1 and ¯1. What I can do now is to create the 1s and ¯1s list, and then scan by +
```
      ⍳4 ⍝ creates range 0..4
0 1 2 3
      2×⍳4
0 2 4 6
      1+2×⍳4
1 3 5 7
      ⍴∘1¨1+2×⍳4 ⍝ for-each create that many 1s
┌─┬─────┬─────────┬─────────────┐
│1│1 1 1│1 1 1 1 1│1 1 1 1 1 1 1│
└─┴─────┴─────────┴─────────────┘
      ⊢∘-\⍴∘1¨1+2×⍳4 ⍝ alternate signs
┌─┬────────┬─────────┬────────────────────┐
│1│¯1 ¯1 ¯1│1 1 1 1 1│¯1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1│
└─┴────────┴─────────┴────────────────────┘
      ∊⊢∘-\⍴∘1¨1+2×⍳4 ⍝ flatten
1 ¯1 ¯1 ¯1 1 1 1 1 1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1
      0,∊⊢∘-\⍴∘1¨1+2×⍳4
0 1 ¯1 ¯1 ¯1 1 1 1 1 1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1
      +\0,∊⊢∘-\⍴∘1¨1+2×⍳4 ⍝ cumulative sum
0 1 0 ¯1 ¯2 ¯1 0 1 2 3 2 1 0 ¯1 ¯2 ¯3 ¯4
```
[Answer]
# [Haskell](https://www.haskell.org/), 47 bytes
```
(#0)
m#n|m>n=[-n..n]++map(0-)(m#(n+1))|1>0=[-m]
```
[Try it online!](https://tio.run/##DcmxCoAgEADQva8QbPAQxaDVfqQcJLIk75Bq9Nu7eus74n1upXDyCyvpoENJDSfysyFrKWiNsSpnQKFUpAeANkzuXwyMMZOvV6ZH9CKJkd81lbjfbNZaPw "Haskell – Try It Online")
[Answer]
# [Java (JDK 10)](http://jdk.java.net/), 98 bytes
```
n->{var s="0";for(int i=0,r=0,d=1;i++<n;s+=" "+r,d=-d)for(r+=d;r!=i&r!=-i;r+=d)s+=" "+r;return s;}
```
[Try it online!](https://tio.run/##ZU6xboMwFNz5iquHCuqCkqFLjDNW6tApY9XBhRA9CjayH0hRxLdTkzRdOtw73b3T6VozmbytvxfqB@cZbdTFyNQVTyr55zWjrZicXZ9J1ZkQ8G7I4pIAw/jVUYXAhiNNjmr08Zce2JM9fXzC@FPIrlHgzfLrb1d5C@zRQC82318m4xG02AjVOJ@SZZDePPuIWm8VSVlaFaQWENJHK6@zNeelrpV/0PQYT05q1dk9pvyRR28R1Lyo64C/amhsVaRS4yWylPeJwOEc@NgXbuRiiBO5sylBQuwgIjWFGYbunFKW3SrnZMW8/AA "Java (JDK 10) – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~17~~ 15 bytes
*-2 bytes thanks to Luis Mendo!*
```
0i:oEqG:EqY"Ysh
```
[Try it online!](https://tio.run/##y00syfn/3yDTKt@10N3KtTBSKbI44/9/UwA "MATL – Try It Online")
Explanation for `n=3`:
```
0		% push 0
 i:		% read input as integer, push range
		% stack: [0, [1 2 3]]
   o		% modulo 2, stack: [0, [1 0 1]]
    Eq		% double and decrement, stack: [0, [1 -1 1]]
      G:	% push input and range again
		% stack: [0, [1 -1 1], [1 2 3]]
        Eq	% double and decrement,
		% stack: [0, [1 -1 1], [1 3 5]]
	  Y"	% run-length decoding
		% stack: [0, [1 -1 -1 -1 1 1 1 1 1]]
	    Ys	% cumulative sum
		% stack: [0, [1  0 -1 -2 -1  0  1  2  3]]
	      h	% horizontally concatenate
		% end of program, automatically print the stack
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~44~~ ~~42~~ 41 bytes
*2 bytes removed thanks to [@StewieGriffin](https://codegolf.stackexchange.com/users/31516/stewie-griffin), and 1 byte further removed thanks to @Giuseppe!*
```
@(n)interp1((t=0:n).^2,-t.*(-1).^t,0:n^2)
```
[Try it online!](https://tio.run/##DYsxCsAgDAB3X@GYFBuqdBKEvkQoVcElig39vvWm4@DaI/eXZwlENC9grCx5dAsg4fCMFJ3ZhTbY7XIxq0WHs7ShWQdt/an0ItW3Q1k7qsxp/g "Octave – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~52~~ 47 bytes
```
f=->n{n<1?[0]:f[n-1]+(2-n..n).map{|x|-~0**n*x}}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y6vOs/G0D7aINYqLTpP1zBWW8NIN09PL09TLzexoLqmoka3zkBLK0@rorb2v4ahnp6ppl5qYnJGdU1JTYFCWnRJbO1/AA "Ruby – Try It Online")
Below is the original 52-byte version with an explanation:
```
f=->n{n<1?[0]:f[n-1]+[(r=*2-n..n).map(&:-@),r][n%2]}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y6vOs/G0D7aINYqLTpP1zBWO1qjyFbLSDdPTy9PUy83sUBDzUrXQVOnKDY6T9Uotva/hqGenqmmXmpickZ1TUlNgUJadAlQGAA "Ruby – Try It Online")
### Walkthrough
```
f=->n{           #Recursive approach
 n<1?[0]         #Init with 0 if n=0
 :f[n-1]         #else make a recursive call
 +               #and append an array of numbers
 [(r=*2-n..n)    #Init r as splatted range from 2-n to n
 .map(&:-@)      #"-@" is unary minus, so this a fancy way to do map{|x|-x} for -1 byte
                 #For even n use this negated r, e.g. for n=4: [2, 1, 0, -1, -2, -3, -4]
 ,r]             #For odd n use r directly, e.g. for n=3: [-1, 0, 1, 2, 3]
 [n%2]           #Odd/even selector
}
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 113 bytes
```
0-I-[0|I].
N-[H|T]-R:-N is -H*(-1)^N,A is N-1,A-[H|T]-R;I is H-(-1)^N,N-[I|[H|T]]-R.
N-O:-X is -N*(-1)^N,N-[X]-O.
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/30DXUzfaoMYzVo/LTzfaoyYkVjfIStdPIbNYQddDS0PXUDPOT8cRxPXTNdRxhCmx9gQJeehCFQC1etaApYByIJP8rXQjwGb4aSGURMTq@uv9t9dVMDTQ9ddRKC/KLEnV8NfU@w8A "Prolog (SWI) – Try It Online")
[Answer]
## Python 3, 83 bytes
```
def c(n):print([(-1)**j*(abs(j-i)-j)for j in range(n+1)for i in range(2*j)][:-n+1])
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~18~~ 17 bytes
```
:ṁoṡ₁ŀ⁰_₁⁰
*^⁰_1⁰
```
[Try it online!](https://tio.run/##yygtzv7/3@rhzsb8hzsXPmpqPNrwqHFDPJABpLi04kAcQyDx//9/EwA "Husk – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 19 bytes
```
Ｆ⊕ＮＩ×∨﹪ι²±¹…·∧ι⁻²ιι
```
[Try it online!](https://tio.run/##FYwxDgIhEAC/QrmbYOHFzspYWdxpjB9AWM9NYDEL3PeRayZTTMZ/nfrsYu@frAZu4pUSSaUw/Nfq0tKbFBDRPJSlwtWVCi9OVOCuMOfQYga2ZkJrFlpdJTji8HGKrfBGTycrwUXCXs0srcBkDe/NAJ57P/XDFv8 "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
  Ｎ                 Input as a number
 ⊕                  Increment
Ｆ                   Loop over implicit range
                ²   Literal 2
                 ι  Current index
               ⁻    Subtract
              ι     Current index
             ∧      Logical And
                  ι Current index
           …·       Inclusive range
       ι            Current index
        ²           Literal 2
      ﹪             Modulo
          ¹         Literal 1
         ±          Negate
     ∨              Logical Or
    ×               Multiply
   Ｉ                Cast to string and implicitly print
```
Alternative explanation:
```
Ｆ⊕Ｎ
```
Loop over the integers from `0` to the input inclusive.
```
Ｉ
```
Cast the results to string before printing.
```
×∨﹪ι²±¹
```
Negate alternate sets of results.
```
…·∧ι⁻²ιι
```
Form a list from the previous index to the current index, excluding the previous index.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~11~~ 12 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
Bah, I thought I had 11 wih `_2+ỊrN)N;¥/`
```
_2+ỊrN×-*$)Ẏ
```
**[Try it online!](https://tio.run/##y0rNyan8/z/eSPvh7q4iv8PTdbVUNB/u6vv//78ZAA)**
### How?
```
_2+ỊrN×-*$)Ẏ - Main Link: n           e.g. 4
          )  - for x in [1...n]:           1       2          3               4
_2           -   subtract 2 from x        -1       0          1               2
   Ị         -   is x insignificant?       1       0          0               0
  +          -   add                       0       0          1               2
     N       -   negate x                 -1      -2         -3              -4
    r        -   inclusive range          [0,-1]  [0,-1,-2]  [1,0,-1,-2,-3]  [2,1,0,-1,-2,-3,-4]
         $   -   last two links as a monad:
       -     -     minus one              -1      -1         -1              -1
        *    -     raised to the power x  -1       1         -1               1
      ×      -   multiply                 [0,1]   [0,-1,-2]  [-1,0,1,2,3]    [2,1,0,-1,-2,-3,-4]
           Ẏ - tighten                    [0,1,0,-1,-2,-1,0,1,2,3,2,1,0,-1,-2,-3,-4]
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 10 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
╗)SΘ█☼₧ΘP(
```
[Run and debug it](https://staxlang.xyz/#p=bb2953e9db0f9ee95028&i=2%0A3&a=1&m=2)
[Answer]
### Scala, 119 Bytes
```
def a(n: Int)={lazy val s:Stream[Int]=0#::Stream.from(0).map{x=>s(x)+1 -2*(Math.sqrt(x).toInt%2)}
s.take(n*n+1).toList}
```
Ungolfed:
```
def a(n: Int)={
  lazy val s:Stream[Int]= 0#::Stream.from(0).map //Give the starting point and indexing scheme
  {
    x=>
    {
      val sign = 1-2*(Math.sqrt(x).toInt%2) //Determine whether we are adding or subtracting at the current index
      s(x)+sign
    }
  }
  s.take(n*n+1).toList //Take the desired values
}
```
This can probably be golfed much better, but I wanted a solution utilizing lazy Streams.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~34~~ 32 bytes
```
⎕CY'dfns'⋄-0,∘∊1↓¨2to/S×¯1*S←⍳,⊢
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1HfVOdI9ZS0vGL1R90tugY6jzpmPOroMnzUNvnQCqOSfP3gw9MPrTfUCn7UNuFR72adR12LQHo8/YF8Ay43IEmUHi6gHiDPTcH0PwA "APL (Dyalog Unicode) – Try It Online")
Requires `⎕IO←0`
-2 bytes thanks to @FrownyFrog
[Answer]
# [Stacked](https://github.com/ConorOBrien-Foxx/stacked), 44 bytes
```
[~>0\:2%\#,2*1-tr[...rep]flatmap,$sumonpref]
```
[Try it online!](https://tio.run/##Ky5JTM5OTfn/P7rOziDGykg1RlnHSMtQt6QoWk9Pryi1IDYtJ7EkN7FAR6W4NDc/r6AoNS32v4NVOheXqUKdnUK0lUJBaYmCuoKuHZAAMdMV8ktLYhXygHr@AwA "Stacked – Try It Online") It's been a while since I programmed in Stacked, but I think I still got it.
## Alternatives
**73 bytes:** `[0\|>:2%tmo*2 infixes[:...|>\rev...|>rev#,$#'sortby 1#behead]flatmap 0\,]`
This goes with the "ranges from generated indices" approach used in my [Attache answer.](https://codegolf.stackexchange.com/a/165122/31957) This proved to be pretty long, since Stacked has no builtin for reversed ranges nor collapsing. (That's what `:...|>\rev...|>rev#,$#'sortby 1#behead` does.)
**53 bytes:** `[0\|>:2%tmo _\tpo#,tr[...rep]flatmap 0\,inits$summap]`
...so I decided to go for an approach which instead finds the cumulative sum (`inits$summap`) over `1` and `-1` repeated by the odd integers, as in the [R answer](https://codegolf.stackexchange.com/a/164978/31957).
**46 bytes:** `[~>0\:2%\#,2*1-tr[...rep]flatmap,inits$summap]`
...but I realized that the negative integers *and* the odd integers could be made in one go, by multiplying both generated arrays (the mod 2 values of the range and the range itself) by `2` then subtracting `1`. This gives alternating `1`s and `-1`s for the first range and the odd integers for the second!
**44 bytes:** `[~>0\:2%\#,2*1-tr[...rep]flatmap,$sumonpref]`
... and then I remembered I had a builtin for mapping prefixes. ^-^
[Answer]
# [Julia 0.6](http://julialang.org/), 44 bytes
```
n->[(i%2*2-1)*[0:i;(n>i)*~-i:-1:1]for i=1:n]
```
[Try it online!](https://tio.run/##yyrNyUw0@x9q@z9P1y5aI1PVSMtI11BTK9rAKtNaI88uU1OrTjfTStfQyjA2Lb9IIdPW0Cov9n9BUWZeSU6eRqiGkaYmF4JnjMIzQeEZGmpqKiDzgdz/AA "Julia 0.6 – Try It Online")
Since OP mentions "the output format is flexible", this prints an array of sub arrays, eg. U(3) => `[[0, 1], [0, -1, -2, -1], [0, 1, 2, 3]]`.
`i%2*2-1` decides the sign of the current subarray - negative for even numbers, positive for odd.
`[0:i;(n>i)*~-i:-1:1]` is in two parts. 0:i is straightforward, the range of values from 0 to the current i. In the next part, ~-i:-1:1 is the descending range from i-1 to 1. But we want to append this only if we're not yet at the final value, so multiply the upper end of the range by (n>i) so that when n==i, the range will be 0:-1:1 which ends up empty (so the array stops at n correctly).
---
And here's a version that can support random access - the inner lambda here returns the i'th term of the sequence without having to have stored any of the terms before it. This one gives the output as a single neat array too.
### 49 47 bytes
```
n->map(i->((m=isqrt(i))%2*2-1)*(m-i+m^2),0:n^2)
```
[Try it online!](https://tio.run/##VcexCoAgEADQvf8I7iwhLRoC/QzHwPFCxcy@/3LM6fGuN5Df2RlO0kafgaQFiIaeu1QgxFELLRUKiJKmeGqclyM1eMiFUg0JHGjE39ZuWzelWvkD "Julia 0.6 – Try It Online")
]


[Question]
      [
For any positive 32-bit integer (`1 ≤ n ≤ 0xFFFFFFFF`) output the number of bits needed to represent that integer.
# Test cases
```
| n    | n in binary | bits needed |
|----------------------------------|
| 1    | 1           | 1           |
| 2    | 10          | 2           |
| 3    | 11          | 2           |
| 4    | 100         | 3           |
| 7    | 111         | 3           |
| 8    | 1000        | 4           |
| 15   | 1111        | 4           |
| 16   | 10000       | 5           |
| 128  | 10000000    | 8           |
| 341  | 101010101   | 9           |
4294967295 => 11111111111111111111111111111111 => 32
```
So `f(16)` would print or return `5`
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest code in bytes wins

[Answer]
# [Dodos](https://github.com/DennisMitchell/dodos), 60 bytes
```
	' S ' g
g
	S dab
	g S ' dab f
f
	f ' '
	S dab
'
	dip
S
	dot
```
[Try it online!](https://tio.run/##S8lPyS/@/59TXSFYQV0hnSudizNYISUxiYszHSwCZCqkcaVxcaYBOeowSSAjJbOAKxhI5Zf8///f0BQA "Dodos – Try It Online")
(`S` computes the sum, `S ' dab f` divides by 2)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 2 bytes
```
bL
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJBIiwiIiwiYkwiLCIiLCIzNDEiXQ==)
### Explained
```
bL
b  # binary
 L # length
```
[Answer]
# 68020 assembler, 2 4 bytes (I think)
```
BFFFO D0, D1
INC D1
```
The BFFFO instruction finds the position of the first set bit in parameter 1, and stores the result in parameter 2. I think it is a 2-byte instruction. Unfortunately, it is indexed from 0, not 1. Hence you need an INC on D1 afterwards.
[Answer]
# [Pushy](https://github.com/FTcode/Pushy), 11 bytes
```
0{${h}2/;}#
```
[**Try it online!**](https://tio.run/nexus/pushy#@29QrVKdUWukb12r/P//f0NTAA)
This works by continually doing `x = x // 2` until `x = 0`, and counting the number of divisions taken:
```
0            \ Push a 0 (initial counter)
 {$     ;    \ While input > 0:
   {h}       \  Increment counter
      2/     \  Floordiv input by 2
         }#  \ Output final counter
```
[Answer]
# [PowerShell](https://github.com/PowerShell/PowerShell) v3+, ~~37~~ 34 bytes
```
param($n)(1..32|?{!($n-shr$_)})[0]
```
[Try it online!](https://tio.run/nexus/powershell#@1@QWJSYq6GSp6lhqKdnbFRjX60I5OkWZxSpxGvWakYbxP7//9/EyNLE0szcyNIUAA "PowerShell – TIO Nexus")
[Answer]
# Groovy, 32 bytes
```
{Long.toBinaryString(it).size()}
```
This is an unnamed closure.
[Try it here !](http://ideone.com/lnngQC)
[Answer]
# MATL, 2 bytes
```
Bn
```
The shortest solution in MATL seems to be just direct, by measuring the length of the binary representation (as a vector). Other options are `ZlkQ`, which takes the base-2 logarithm, floors it and adds 1, or `YBn` which converts the input to a binary string and finds the length.
[Answer]
# J, 4 bytes
```
#&#:
```
**Explanation:**
```
#      NB. Counts length of bit list
&      NB. Connects # and #:
#:     NB. Creates list of bits
```
[Answer]
## [K](https://en.wikipedia.org/wiki/K_(programming_language))/[Kona](https://github.com/kevinlawler/kona), 4 bytes
```
#2\:
```
`\:` gets the representation of right-hand in base left-hand - in this case, base 2 of the input. `#` then just counts this
```
k)2\:341
1 0 1 0 1 0 1 0 1
k)#2\:341
9
```
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 70 bytes
```
[S S S N
_Push_0][S N
S _Duplicate_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][N
S S N
_Create_Label_LOOP][S N
S _Duplicate][N
T   S S N
_If_0_jump_to_Label_PRINT][S S S T  S N
_Push_2][T  S T S _Integer_division][S N
T   _Swap_top_two][S S S T  N
_Push_1][T  S S S _Add][S N
T   _Swap_top_two][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT][S N
N
_Discard_top][T N
S T _Print_integer]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.
`[..._some_action]` added as explanation only.
[Try it online](https://tio.run/##K8/ILEktLkhMTv3/X0FBgQsIgYiTixMEuCACXJwgWkGBE8QCsTlBHDAJZAPlubggWkEczv//TYwsTSzNzI0sTQE) (with raw spaces, tabs and new-lines only).
**Explanation in pseudo-code:**
```
Integer i = STDIN as integer
Integer r = 0
Start LOOP:
  if i is 0:
    Call function PRINT_AND_EXIT
  i = i integer-divided by 2
  r = r + 1
  Go to next iteration of LOOP
function PRINT_AND_EXIT:
  Print r as integer
  Exit with error
```
**Example run (`n=16`):**
```
Command   Explanation                 Stack       HEAP     STDIN   STDOUT  STDERR
SSSN      Push 0                      [0]
SNS       Duplicate top (0)           [0,0]
SNS       Duplicate top (0)           [0,0,0]
TNTT      Read STDIN as integer       [0,0]       {0:16}   16
TTT       Retrieve                    [0,16]      {0:16}
NSSN      Create Label_LOOP           [0,16]      {0:16}
 SNS      Duplicate top (16)          [0,16,16]   {0:16}
 NTSSN    If 0: Jump to Label_PRINT   [0,16]      {0:16}
 SSSTSN   Push 2                      [0,16,2]    {0:16}
 TSTS     Integer-divide (16/2)       [0,8]       {0:16}
 SNT      Swap top two                [8,0]       {0:16}
 SSSTN    Push 1                      [8,0,1]     {0:16}
 TSSS     Add (0+1)                   [8,1]       {0:16}
 SNT      Swap top two                [1,8]       {0:16}
 NSNN     Jump to Label_LOOP          [1,8]       {0:16}

 SNS      Duplicate top (8)           [1,8,8]     {0:16}
 NTSSN    If 0: Jump to Label_PRINT   [1,8]       {0:16}
 SSSTSN   Push 2                      [1,8,2]     {0:16}
 TSTS     Integer-divide (8/2)        [1,4]       {0:16}
 SNT      Swap top two                [4,1]       {0:16}
 SSSTN    Push 1                      [4,1,1]     {0:16}
 TSSS     Add (1+1)                   [4,2]       {0:16}
 SNT      Swap top two                [2,4]       {0:16}
 NSNN     Jump to Label_LOOP          [2,4]       {0:16}

 SNS      Duplicate top (4)           [2,4,4]     {0:16}
 NTSSN    If 0: Jump to Label_PRINT   [2,4]       {0:16}
 SSSTSN   Push 2                      [2,4,2]     {0:16}
 TSTS     Integer-divide (4/2)        [2,2]       {0:16}
 SNT      Swap top two                [2,2]       {0:16}
 SSSTN    Push 1                      [2,2,1]     {0:16}
 TSSS     Add (2+1)                   [2,3]       {0:16}
 SNT      Swap top two                [3,2]       {0:16}
 NSNN     Jump to Label_LOOP          [3,2]       {0:16}
 SNS      Duplicate top (2)           [3,2,2]     {0:16}
 NTSSN    If 0: Jump to Label_PRINT   [3,2]       {0:16}
 SSSTSN   Push 2                      [3,2,2]     {0:16}
 TSTS     Integer-divide (2/2)        [3,1]       {0:16}
 SNT      Swap top two                [1,3]       {0:16}
 SSSTN    Push 1                      [1,3,1]     {0:16}
 TSSS     Add (3+1)                   [1,4]       {0:16}
 SNT      Swap top two                [4,1]       {0:16}
 NSNN     Jump to Label_LOOP          [4,1]       {0:16}
 SNS      Duplicate top (1)           [4,1,1]     {0:16}
 NTSSN    If 0: Jump to Label_PRINT   [4,1]       {0:16}
 SSSTSN   Push 2                      [4,1,2]     {0:16}
 TSTS     Integer-divide (1/2)        [4,0]       {0:16}
 SNT      Swap top two                [0,4]       {0:16}
 SSSTN    Push 1                      [0,4,1]     {0:16}
 TSSS     Add (4+1)                   [0,5]       {0:16}
 SNT      Swap top two                [5,0]       {0:16}
 NSNN     Jump to Label_LOOP          [5,0]       {0:16}
 SNS      Duplicate top (0)           [5,0,0]     {0:16}
 NTSSN    If 0: Jump to Label_PRINT   [5,0]       {0:16}
NSSSN     Create Label_PRINT          [5,0]       {0:16}
 SNN      Discard top                 [5]         {0:16}
 TNST     Print as integer            []          {0:16}           5
                                                                            error
```
Program stops with an error: No exit found.
[Answer]
# [Befunge-98 (PyFunge)](https://pythonhosted.org/PyFunge/), ~~19~~ 16 bytes, Thanks to @JoKing
```
&#\<_$.@j3:/2\+1
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tNAtqAQz//9XU46xiVfRc8gyttI3itE2/P/fzFgBAA "Befunge-98 (PyFunge) – Try It Online")
19 bytes:
```
&0#;1+\2/:!3j@.$_\;
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tNAtqAQz//9XM1C2NtSOMdK3UjTOctBTiY@x/v/fzFgBAA "Befunge-98 (PyFunge) – Try It Online")
5 bytes shorter than Befunge-93 :)
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 48 bytes
```
({<({<(({}[()]))>{()(<{}({}[()])>)}{}}{})>()}{})
```
[Try it online!](https://tio.run/##SypKzMzTTctJzP7/X6PaBoQ0qmujNTRjNTXtqjU0NWyqa2ECdpq11bVApGmnAWJp/v9vaGQBAA "Brain-Flak – Try It Online")
Readable version:
```
({< # Start a loop
  #devide by two:
  ({<(({}[()]))>{()(<{}({}[()])>)}{}}{})
>()} # Count interations
{} # pop the zero
) # push the result
```
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2) `L`, 1 byte
```
ḃ
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728JKM0Ly_faGm0ko9S7IKlpSVpuhaLH-5oXlKclFwM5S9YbGxiCGECAA)
`ḃ` converts to binary; the `L` flag takes the length.
]