TI-Basic, 45 bytes
Input NFor(B,2,NIf prod(seq(BfPart(iPart(N/B^X)/B),X,0,log(N)/log(B))<2Disp BEnd
Explanation
- Input N
- For every B from 2 to N
- If N is just 0 and 1 in base B
- Display B
- If N is just 0 and 1 in base B
- End loop
The complicated part
The second line works as follows:
- For every X from 0 to logB N
- B × fPart(iPart(N / BX) / B) is the Nth digit in base B, counting backwards
- Consider this as a list
- For each element, if the digit is less than 2, yield 1 (true), else 0 (false)
- Take the product: 1 iff all elements are 1
Note
The program runs significantly faster if a closing parenthesis )
is placed at the end of the second line. See here for more about this.