[Question]
  [
[Related](https://codegolf.stackexchange.com/q/257458/119451).
Given a positive integer \$n\$, output all integers \$b\$ (such that \$1<b<n-1\$) where \$n\$ can be written as the sum of any number of consecutive powers of \$b\$.
**Example:**
Let's say \$n=39\$.
\$3^1+3^2+3^3\$   
\$= 3 + 9 + 27\$   
\$= 39\$
This does not work for any other \$b\$, so our output is `[3]`.
**Test cases up to \$n=50\$:**
```
1: []
2: []
3: []
4: [2]
5: []
6: [2]
7: [2]
8: [2]
9: [3]
10: []
11: []
12: [2,3]
13: [3]
14: [2]
15: [2]
16: [2,4]
17: []
18: []
19: []
20: [4]
21: [4]
22: []
23: []
24: [2]
25: [5]
26: []
27: [3]
28: [2]
29: []
30: [2,5]
31: [2,5]
32: [2]
33: []
34: []
35: []
36: [3,6]
37: []
38: []
39: [3]
40: [3]
41: []
42: [6]
43: [6]
44: []
45: []
46: []
47: []
48: [2]
49: [7]
50: []
```
**Clarifications:**
* You can use [this Python script](https://tio.run/##VY/BDoIwEETvfMUcW4IH5SQJX0I42FB0SV0JLQn9@tqiAs71zezMjt49XlyGTvewszJknRVGVhmi@tcEAjGmG9@1MJoj@rIfH3ZOB5TkSZsOphkqagOjjk4niMfZCSmzFFZ7@FKAT@dDsU1sm9TkHxvL9tDi49FGIc@xrJllzbQbp/TUU3iJugb/rxunNEcV8DKE8voG) to generate your own test cases.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer wins!
  
[Answer]
# [JavaScript (V8)](https://v8.dev/), 62 bytes
Prints the results.
```
n=>{for(b=1;i=++b<n-1;k||print(b))for(k=n;k%b?i--:k/=b;)k-=!i}
```
[Try it online!](https://tio.run/##FcrRCsIgFMbx@57iJASKWHkRRO7Ug0QXc2xhynE42c22Zzd39f/g9/3auZ265Mas5nsZsBA@lyEmblEbh1LahpQ2fl3H5ChzK8SuHsn4k305pR7@gtYIr/DotrJj6DMQIGhT0yDcrnVIKWA5AHSRphj6c4hfzt6EDGR9SWAfJkz1gVPtVv4 "JavaScript (V8) ‚Äì Try It Online")
### Algorithm
Given the input \$n\$ and for each \$b\in[2,n-2]\$:
1. we do \$n\gets n/b\$ as long as \$n\equiv 0\pmod b\$
2. we do \$n\gets (n-1)/b\$ as long as \$n-1\equiv 0\pmod b\$
If we end up with \$n=0\$, then \$b\$ is a solution.
### Explanation
If \$n\$ is of the form \$b^p+b^{p+1}+\dots+b^{p+q}\$, the first step will normalize it to:
$$b^0+b^1+\dots+b^q$$
and each iteration of the second step will remove the most significant term ...
$$b^0+b^1+\dots+b^{q-1}$$
... until it's eventually reduced to \$0\$.
---
### [C (gcc)](https://gcc.gnu.org/), 79 bytes
Essentially the same code.
```
b,i,k;f(n){for(b=1;i=++b<n-1;k||printf("%d ",b))for(k=n;k%b?i--:(k/=b);)k-=!i;}
```
[Try it online!](https://tio.run/##NY7LDoIwEEX3fMVIQtKmNNKFG4bGb6ElxaY6EERdAL9u5RF3J/eRe61srY3R5D4P6BjxyXUDM1qh10KYiqTCMM/94Gl0LM0aSHPD@RYKmjBk5uqlLFk4a8ORB6lPHpf47nwDj9oT4zAlAGsbCFfYigQaFAJBpeFSrCDEkQL475DOmnKdAuK4G9u1g/rXaG/1wFSxC0uyxK9197p9Rvn5AQ "C (gcc) ‚Äì Try It Online")
I wish it could be rearranged to get rid of `:(k/=b)`. The obvious way is `k%b<1?k/=b:i--`, but that's just as long.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 73 [bitsv2](https://github.com/Vyxal/Vyncode/blob/main/README.md), 9.125 bytes
```
‚á©·∏¢'? Äe√ûS·π†?c
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyJBPSIsIiIsIuKHqeG4oic/yoBlw55T4bmgP2MiLCIiLCIxXG4yXG4zXG40XG41XG42XG43XG44XG45XG4xMFxuMTFcbjEyXG4xM1xuMTRcbjE1XG4xNlxuMTdcbjE4XG4xOVxuMjAiXQ==)
Formulas? No we do things brute force around here.
## Explained
```
‚á©·∏¢'? Äe√ûS·π†?c¬≠‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å£‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å¢‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å§‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå¬≠
‚á©·∏¢'          # ‚Äé‚Å°Keep all from the range [2, n - 2] where:
      √ûS·π†    # ‚Äé‚Å¢  Sums of sublists of
   ? Äe       # ‚Äé‚Å£  The number raised to each number in the range [0, input]
         ?c  # ‚Äé‚Å§  Contains the input
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~24~~ 20 bytes
```
ÔºÆŒ∏Ôº©Œ¶‚Ä¶¬≤‚äñŒ∏¬¨‚äô‚™™‚çòŒ∏Œπ0‚ÅªŒªÔº©¬¨Œº
```
[Try it online!](https://tio.run/##LYzNCsIwEITvPkXoaQMRtNee/EHwYBH7BGtcaiDZtslG8OljFOcwh5n5xj4x2gl9KWees/Q53CnCorvVNToWOGASODkvNb0hjwStUUeykQKx0KNOtVH9JLDjNwyzdwJ7TDRIxUdYjHK1bzZN9YvjnMAb9Tv9MkH/1ZWybcv65T8 "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation: When converted to base `b`, `n` has to have the form `1+0*`, thus when split on `0` the first part can only contain `1`s and the other parts must be empty, although the code "permits" `0`s.
```
ÔºÆŒ∏                      Input `n` as a number
    ‚Ä¶                   Range from
     ¬≤                  Literal integer `2` to
       Œ∏                Input `n`
      ‚äñ                 Decremented
   Œ¶                    Filtered where
            Œ∏           Input `n`
           ‚çò            Converted to base
             Œπ          Current value
          ‚™™             Split on
              0         Literal string `0`
        ¬¨‚äô              All parts satisfy
                Œª       Current part
               ‚Åª        Only contains occurrences of
                   Œº    Inner index
                  ¬¨     Logical Not
                 Ôº©      Cast to string
                        Implicitly print
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
¬Ω·∏äbt0·ªä∆ë…ó@∆á
```
A monadic Link that accepts a positive integer and yields a list of all valid integer bases.
**[Try it online!](https://tio.run/##ASYA2f9qZWxsef//wr3huIpidDDhu4rGkcmXQMaH/8OHxZLhuZj//zE1Ng "Jelly ‚Äì Try It Online")**
### How?
A base, \$b\$, works for \$n\$ when \$n\$ converted to base \$b\$ is a run of ones optionally followed by a run of zeros.
No \$b > \sqrt{n}\$ can work since the \$b^2\$ term breaks the bank on its own and the \$b^1\$ and \$b^0+b^1\$ solutions are the excluded cases \$b\ge n-1\$.
```
¬Ω·∏äbt0·ªä∆ë…ó@∆á - Link: positive integer, n
¬Ω          - square-root {n}
 ·∏ä         - dequeue -> B = [2,3,4,...,floor(sqrt(n))]
         ∆á - keep those {b in B} for which:
       …ó@  -   last three links as a dyad with swapped arguments - f(n, b):
  b        -     convert {n} to base {b}
   t0      -     trim zeros (e.g. [4,0,1,0,0,0] -> [4,0,1])
      ∆ë    -     is invariant under?:
     ·ªä     -       insignificant? (abs(digit)<=1 vectorised)
```
[Answer]
# [Python](https://www.python.org), 82 bytes
*-1 byte, thanks to xnor*  
*-1 byte, thanks to Arnauld*
```
lambda n:[b for b in range(2,n-1)for i in range(n*n)if~-b*n==b**(i%n+1)-b**(i//n)]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3g3ISc5NSEhXyrKKTFNLyixSSFDLzFIoS89JTNYx08nQNNUGCmQjBPK08zcy0Ot0krTxb2yQtLY1M1TxtQ01dMFNfP08zFmqyMppGUwNNKy4FhYKizLwSjUydNI1MTU2I0gULIDQA)
Uses the equation \$\sum\_{k=i}^{j}b^k = \frac{b^{j+1}-b^i}{b-1}\$
[Answer]
# [Haskell](https://www.haskell.org/), 54 bytes
```
f n|r<-[0..n]=[i|i<-[2..n-2],a<-r,b<-r,n*i-n==i^a-i^b]
```
[Try it online!](https://tio.run/##XZLRboMgFIbvfYpzsYt2gUYOqG0iT2JoYjeXkXZkUS99dwdtIv7zgvgB5@Tjh@9@ug@Px7p@UVjGVnbl6RSc7fziI3AEyU70rRzFLQ3h3ctgrb/20l9vbv3pfSBLv6MPM71RHz6pi63IWhppoUMQNB6plTQP0/zRT8PkimL7j5VdQfE7KEGdO4oX8B70HkwE3qjaL9Ww1ACdgS6R9Eaq3HdRIKKSCYvdZo216KMqxKeSMHmigeZnoAskkKRyIStECIghIUYlTkpVxhr2NnAaxpgYjHT5PExupdX/CYZyDVraAMHN6SSlRZ0nICcNOWm8PVMiwvWZZJTbGo0ISgaUDORkwMdgTCYJNflNvp6TK9Y/ "Haskell ‚Äì Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~55~~ 56 bytes
```
->n{(2..n-2).select{|x|/^[0_]*(1_)+1$/=~n.digits(x)*?_}}
```
[Try it online!](https://tio.run/##FcvdCkAwGADQVxEuNvIx5XI8iFj@UyzZ1DSfV5@c@3Ne/e1m7pJSWpIDyCSnoKZtGrR9zJO2dSaaiDBBYxam/JUwrsuqFTE0qgSiOy6tPMIAiozC3h3/8gNr0AvsXJsGfXQf "Ruby ‚Äì Try It Online")
If a number `n` is the sum of consecutive powers of `x`, then its representation is base `x` is a sequence of `1`s followed by any number of zeroes.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), ~~28~~ 26 bytes
```
{2+&x{i~!#i:&y\x}'-1_2_!x}
```
-2 thanks to @coltim
[Try it online!](https://ngn.codeberg.page/k#eJxLs6o20larqM6sU1TOtFKrjKmoVdc1jDeKV6yo5eJKUzfUVjQ14AIA4QwKaA==)
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata), 9 bytes
```
‚Üê·∂†{·µàqE≈Ø‚àë=
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFZtJJurlLsgqWlJWm6FpsetU14uG1B9cOtHYWuR9c_6phou6Q4KbkYKr3gpqMhlxGXMZcJlymXGZc5lwWXJZehAZehIZehEZehMZehCZehKZehGZehOZehBZehJZeRAZcRUI8Rl5Exl5EJl5EpxCQA)
```
‚Üê·∂†{·µàqE≈Ø‚àë=
‚Üê           Decrement
 ·∂†{         Filter the range [0, n) by:
   ·µàq           Find any subsequence of the range [0, input)
     E          Power
      ≈Ø         Check that it does not contain duplicates
                    so that the base is not 1
       ‚àë        Sum
        =       Check that it is equal to the input
```
---
# [Nekomata](https://github.com/AlephAlpha/Nekomata), 10 bytes
```
‚Üê·∂†{1>B:o¬±=
```
[Attempt This Online!](https://ato.pxeger.com/run?1=LY4rbgJRGEb9Wcb4Se7_uC-SIthGg4CmNWRAMFX1VQh8zQggOIJhAeyisl1JJyn6yznn-zqvX1ebbtEvTs9N2zXz4fjev7Xl8vu5_7kNHzKdTTb369Nhu3zZPrbheycohhNJZAoVCYggihjiSEQSkpGCVDSgI6OooY5GNKEZLWjFAibYqDTMsYglLGMFq3jABVd8LDoe8YRnvOCVGP5P_QE)
A port of [@Jonathan Allan's Jelly answer](https://codegolf.stackexchange.com/a/264952/9288).
```
‚Üê·∂†{1>B:o¬±=
‚Üê           Decrement
 ·∂†{         Filter the range [0, n) by:
   1>           Check that it is greater than 1
     B          Convert the input to that base
      :  =      Check that it is invariant under:
       o          Sort
        ¬±         Sign
```
Now I regret supporting converting to base 1, otherwise that `1>` could be omitted.
[Answer]
# [Haskell](https://www.haskell.org), 74 bytes
```
0#i=[]
n#i=mod n i:div n i#i
f n=[i|i<-[2..n-2],all(==1)$snd$span(<1)$n#i]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XZM9boMwGIaHbhyh0yclA0gmwj9AUsUX6BUQAypEtUrcKNBOuUmXLFXP1J6mdlAxb1nMY_N9evzafHw9N8NL1_fX6-fbeEi334_Zyuiqjqwbjq8tWTIPrXn348pEB7K6MhezTyux2dhU1Kzp-1hrnqwH266HU2PjvQNXXk8df-7uj42xpOl0NnakNTW2pcp1Iq3pTBeKLaNzQvuUxm4Yn5qhG-oomt9dZRWRe2LOqKoTNoFYglyCciBmypdLBSyVQFugnSM5E8-WXTiIcG8i2OJjibXow3PEmxJTYaKE5lugHSTgpUKh4IgQkICEBCoJr5QHLODbEnYjMCYBRjK7bSa0kvz_hIByCVpSAcHJSS8lWREmICcJOUk8PZUhwvEpbxTaKokISgqUFOSkwEdhTMoLleFOTtepjqZf5O_n-wU)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~12~~ 11 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
tL¬¶ íI√ùm≈íOI√•
```
-1 byte thanks to *@MTN* by porting `tL¬¶` from [*@JonathanAllan*'s Jelly answer](https://codegolf.stackexchange.com/a/264952/52210).
[Try it online](https://tio.run/##yy9OTMpM/f@/xOfQslOTPA/PzT06yd/z8NL//40tAQ) or [verify all test cases](https://tio.run/##yy9OTMpM/W9q4Opnr6TwqG2SgpK936GV/0t8Di07NenQusNzc49O8gfSS//X6vwHAA).
**Explanation:**
```
t        # Get the square-root of the (implicit) input-integer
 L       # Pop and push a list in the range [1,floor(sqrt(input))]
  ¬¶      # Remove the leading 1 to make the range [2,floor(sqrt(input))]
 í        # Filter this list by:
 I√ù      #  Push a list in the range [0,input]
   m     #  Take the current integer to the power of each of these values
    ≈í    #  Get all sublists of this list
     O   #  Sum each inner sublist
      I√• #  Check whether the input is in this list of sums
         # (after which the filtered list is output implicitly as result)
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 58 bytes
```
Select[r=Range[0,#-2],Tr/@Subsequences[#^r]&/*MemberQ[#]]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277Pzg1JzW5JLrINigxLz012kBHWdcoViekSN8huDSpOLWwNDUvObU4WjmuKFZNX8s3NTcptSgwWjk2Vu1/QFFmXom@Q2BpZmqJg1a6voMCxAxDHVOD2P8A "Wolfram Language (Mathematica) ‚Äì Try It Online")
-2 bytes from @att
[Answer]
# [Perl 5](https://www.perl.org/), 88 bytes
```
sub{grep{$x=$_;join('+',map$x**$_,0..$n)=~/\b.+\b(??{$n-eval$&?$;:""})/}2..sqrt($n=pop)}
```
[Try it online!](https://tio.run/##bZFNc5swEIbP1a/YqGowMeFDkj8CYZx7Z5pLb8GTsWvw0DqCAGnc8bh/3V2xmpzKYd/VavXsK9GW3WF2MQ28bzpTm30PfLvpyvem2/GMiSq/9G/b074r25M45uI5@9nUZuJNveBl04rjzY14DuIwFMbP/0bFNpwW28lqdRLmtvy9OYjrlchSzs9@dJZh2L92w0SYvG1a/3zJWNV0E@jbQz1EhYmC@3vOwWdJCk9rJseoxqgxyjWbjYs5LRYkS5I7FLVmSTy2JIRILEMGtq7cviMlM6cjLNCYLejIkuSOPFgcbsrEKZmS5Eo6mLSwGeqcyguaJZ01SSwVj6OwTyUfmaQWRUClSeieyuJUMMeMvCnyptxddeyULqstC5u1ckowTTBN3jSRtLOmLWqBD0vPxk4M8Hv5g/8oeCiPrZ9HxW4a7bOx/tmUxwHqCoS5ylX8n6JeZo7wsG@G/FpUSPKp1na1GSr@5XbeA5gU@7GIM8ofQ7lLwY7DAh7DHGNheMA@cZtyKF@B2wYOK/CaXx6k4H17/A6PX72MnS//AA "Perl 5 ‚Äì Try It Online")
[Answer]
# [Scala 3](https://www.scala-lang.org/), 85 bytes
```
n=>for{b<-2 to n-2;i<-0 to n*n-1;if(b-1)*n==math.pow(b,i%n+1)-math.pow(b,i/n)}yield b
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TU2xTsMwEN37FU9ISHGDISlCQmlciZGBqepUdbDbuBxyL8V1QVWVz2BiCQP8U_8GN2FAp7v37t67u8-f3VI7fduePmrzUi0DnjQxjgNgVVlsYpNov94VePBeH-bT4InXC1FgxhSgOidga4-EUEpk2HMgh7tM_GnANu4Ex9GQ4iJGCpuQEJ3aDM4Zy5t2sAUeOajJtHqdR7KA-t4HK-9PM1aT-ONoSjlCqMFyNKZSZh0fsszHZBMjczFkpTY6PF9v6_fEXNElp7mQ_yc3LJoDVW4F0x__anps2x5_AQ)
---
Uses the equation \$\sum\limits\_{k=i}^{j}b^k = \frac{b^{j+1}-b^i}{b-1}\$
]