[Question]
  [
## Challenge:
Given a positive number \$n\$, convert it to binary, and output a [sequence](/questions/tagged/sequence "show questions tagged 'sequence'") where all `1`s form a top-left to bottom-right diagonal line, including a leading column of `1`s. To give two examples:
\$n=1\$ will result in `[1,3,5,9,17,33,65,129,...]`, with binary values:
```
1
11
101
1001
10001
100001
1000001
10000001
‚Üì       ‚Üò
```
\$n=89\$ will result in `[89,153,281,537,1049,2073,4121,8217,...]`, with binary values:
```
1011001
10011001
100011001
1000011001
10000011001
100000011001
1000000011001
10000000011001
‚Üì         ‚Üò‚Üò  ‚Üò
```
In general, the binary sequences are formed by replacing the leading `1` with `10` in every iteration, with the exception of \$n=1\$.
## Challenge rules:
* The input \$n\$ is guaranteed to be positive.
* Default [sequence](/questions/tagged/sequence "show questions tagged 'sequence'") rules apply, so you're allowed to:
	+ Take an additional input \$k\$ and output the \$k^{th}\$ value of the sequence, either 0-index or 1-index.
	+ Take an additional input \$k\$ and output the first \$k\$ values of the sequence.
	+ Output the values of the sequence indefintely.
* Of course, any reasonable output format can be used. Could be as strings/integers/decimals/etc.; could be as an (infinite) list/array/stream/generator/etc.; could be output with space/comma/newline/other delimiter to STDOUT; etc. etc.
	+ I/O as binary isn't allowed for this challenge, since it's already easy enough as is.
**Please state what I/O and sequence output-option you're using in your answer!**
## General Rules:
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins.  
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
* [Standard rules apply](https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/2422#2422) for your answer with [default I/O rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/), so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
* [Default Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* If possible, please add a link with a test for your code (e.g. [TIO](https://tio.run/#) or [ATO](https://ato.pxeger.com/run)).
* Also, adding an explanation for your answer is highly recommended.
## Test Cases:
```
n     First 10 values of the output sequence
1     [1,3,5,9,17,33,65,129,257,513,...]
2     [2,4,8,16,32,64,128,256,512,1024,...]
3     [3,5,9,17,33,65,129,257,513,1025,...]
6     [6,10,18,34,66,130,258,514,1026,2050,...]
7     [7,11,19,35,67,131,259,515,1027,2051,...]
12    [12,20,36,68,132,260,516,1028,2052,4100,...]
31    [31,47,79,143,271,527,1039,2063,4111,8207,...]
89    [89,153,281,537,1049,2073,4121,8217,16409,32793,...]
111   [111,175,303,559,1071,2095,4143,8239,16431,32815,...]
1000  [1000,1512,2536,4584,8680,16872,33256,66024,131560,262632,...]
```
  
[Answer]
# [Python](https://www.python.org), 39 bytes
```
lambda n,k:n^-2&(1^1<<k)<<len(bin(n))-3
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY31XMSc5NSEhXydLKt8uJ0jdQ0DOMMbWyyNW1sclLzNJIy8zTyNDV1jSHKbzFGFxRl5pVoRKdpGOpkaqblFylkKmTmKRQl5qWnahgaaMZqcsFVGBFUYUxQhRlBFeYEVRgS4RDCvrGwJGyRIWFjDA0MDHAogoTxggUQGgA)
## Explanation
```
lambda n,k:n^-2&(1^1<<k)<<len(bin(n))-3
           n^                             # change bits
             -2&                          # keep lowest bit
                (1^1<<k)                  # 1 0000 1  (k-1 zeros)
                        <<len(bin(n))-3   # shifted to highest bit
```
---
# [Python](https://www.python.org), 49 bytes
*simple string based solution, the n&1 is needed to satisfy the test-case for input 1*
```
lambda n,k:n&1|int((s:=bin(n))[:3]+k*"0"+s[3:],2)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3DXMSc5NSEhXydLKt8tQMazLzSjQ0iq1skzLzNPI0NaOtjGO1s7WUDJS0i6ONrWJ1jDShGs8UFIHURqdpGOpkaqblFylkKmTmKRQl5qWnahgaaMZqcsFVGBFUYUxQhRlBFeYEVRjicgjETwsWQGgA)
[Answer]
# [JavaScript (V8)](https://v8.dev/), 41 bytes
Prints the sequence 'indefinitely' (in practice, until the call stack overflows).
```
f=(n,k=2)=>k*2>n?print(n)|f(n+k):f(n,k*2)
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNEts/j/P81WI08n29ZI09YuW8vILs@@oCgzr0QjT7MmTSNPO1vTKg0kr2Wk@T9Nw8JS8z8A "JavaScript (V8) ‚Äì Try It Online")
### Commented
```
f = (         // f is a recursive function taking:
  n,          //   n = input
  k = 2       //   k = power of 2 to be added to n
              //       the minimum is 2, because of
              //       the edge case n = 1
) =>          //
k * 2 > n ?   // if k * 2 is greater than n:
  print(n)    //   print n
  | f(n + k)  //   and do a recursive call with n + k
:             // else:
  f(n, k * 2) //   do a recursive call with k doubled
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 8 bytes
```
¬°(Y3·∏ã:.·∏ã
```
[Try it online!](https://tio.run/##yygtzv7//9BCjUjjhzu6rfSAxP///w0B "Husk ‚Äì Try It Online")
When your language does not have logarithms you need to get creative with base conversion. Here's some fun with half bits!
Takes a positive integer as input and outputs an infinite list of the sequence starting from that number.
### Explanation
```
¬°(Y3·∏ã:.·∏ã
¬°(        Infinitely repeat the following commands and collect outputs in a list:
       ·∏ã    Convert to base 2
     :.     Prepend 0.5 as an extra initial digit
    ·∏ã       Convert back from base 2
  Y3        Take the maximum between the obtained value and 3
```
As the challenge states, this sequence can be generated by replacing the leading `1` in the binary representation of each value with `10`. If we allow our "binary" number to have digits higher than 1, we could simply add 1 to the first digit (e.g. \$5\_{10} = 101\_2 \rightarrow 201\_{"2"} = 1001\_{2} = 9\_{10}\$). Even better, adding 1 to a digit in base 2 is equivalent to adding 0.5 to the digit preceding it! (\$201\_{"2"} = [0.5][1][0][1]\_{2.0} = 1001\_2\$; I think I'm starting to get *too* creative with notation here).
Taking the maximum between the resulting number and 3 was the shortest way I could find to fix the edge case for 1.
[Answer]
# [Python 2](https://docs.python.org/2/), 41 bytes
A function that takes \$ n \$ as input, and outputs the sequence indefinitely.
```
def f(n):print n;f(n^3<<len(bin(n))-3&-2)
```
[Try it online!](https://tio.run/##K6gsycjPM/r/PyU1TSFNI0/TqqAoM69EIc8ayIkztrHJSc3TSMrMA8po6hqr6Rpp/k/TsLDU/A8A "Python 2 ‚Äì Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
Œªbg<1Mo‚ÇÅ+
```
[Try it online!](https://tio.run/##yy9OTMpM/f//3O6kdBtD3/xHTY3a//8bAQA "05AB1E ‚Äì Try It Online") or [try all testcases.](https://tio.run/##yy9OTMpM/V9Waa@koGunoGRf@f/c7qR0G0Pf/EdNjdr/a0MOLVbSUVA6vNceSOnp6Snp/I821FEw0lEw1lEw01Ew11EwBHGAYhaWQLYhkGFoYGAQCwA "05AB1E ‚Äì Try It Online")
## Explanation
```
Œª         # recursively start with f(0) = n
 bg<       # push floor(log2(f(i-1)))
 1M        # max(1, floor(log2(f(i-1))))
 o         # 2**max(1, floor(log2(f(i-1))))
 ‚ÇÅ+        # f(i) = f(i-1) + 2**max(1, floor(log2(f(i-1))))
```
[Answer]
# [Haskell](https://www.haskell.org), 35 bytes
```
(%2)
n%k|k*2>n=n:(n+k)%k|l<-k*2=n%l
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ0W0km5yQYFS7NI0BVuFmKWlJWm6FjeVNVSNNLnyVLNrsrWM7PJs86w08rSzNYH8HBtdoJBtnmoOVKlHbmJmHlBrbmKBr4JGQVFmXomCnkJJYnaqgqEBkJWmqRBtqKNgpKNgrKNgpqNgrqNgCOIAxSwsgWxDIMPQwMAgFmLeggUQGgA)
Port of [Arnauld's JavaScript answer](https://codegolf.stackexchange.com/a/265875/56433).
[Answer]
# Excel, ~~41~~ 53 bytes
```
=DECIMAL(10^B1&TEXTAFTER(BASE(A1,2),1),2)+IF(B1,A1=1)
```
Inputs *n* and *k* in cells `A1` and `B1` respectively, where *k* represents the *k*th 0-indexed value of the sequence.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 13 bytes
```
(3|2/2,1_2\)\
```
[Try it online!](https://ngn.codeberg.page/k#eJx9kr1SwzAQhHs/RUhmsD05nPuRTrJTQEHj3h1mDE3oKaiYPDurKDVupNF8d7e758vU2a+elGTTtV+b5tTIrnxvQkaRRpJEZuSRREfSmCiK0TAM741WUClQJnEyJQ/AMjAHhqasobJW2X9ago2V9co6nkgyWSDH3RhoBhoK6qQcufKp8olESEaySI67CfgRfCx8KrxUXrQaVLyROTnUQ7s6gy5TiwOO8CV8H2FS5QuFRAkOgpEmoYjGwgYX7AYeCrJyqkV5vBVl4BF4Bm4FDwVPBdeCIw3xwBCuabxHi0Y3icVRimSM4GBGGDOVx4haKMiKyaiFLEP7e3wQzaUWBwYXlxEmQ8xYk2e8eU6KBZQluZcNIasI8+rqyOHWBH/CPMk2vzxeu/mZ2v1pXfd92z0c5omnj8/vr5+d9E03n1/PSz8deee7tJ2mGWVDOzfL1A3tk2x72q99uzTL9TK0x+5Jjod2Oc998wfDv3ww)
A base conversion trick that works somewhat like Husk or Nekomata answers, but keeps things in integers. This works by replacing the leading 1 with a 2 in the binary representation.
```
(3|2/2,1_2\)\
(          )\    collect first k iterations:
         2\      convert to base 2
     2,1_        remove the leading 1 and attach a 2
   2/            convert from "base 2" to integer
 3|              max with 3 to handle 1
```
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), ~~8.5~~ 7.5 bytes (15 nibbles)
```
`.$+^2,:>2``@
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708LzMpKSe1eMGCpaUlaboWaxP0VLTjjHSs7IwSEhwgYlCpJdEWlrFQNgA)
```
`.$+^2,:>2``@    # full program
`.$+^2,:>2``@$$$ # with implicit arguments shown;
`.               # iterate while unique (in this case, for ever),
  $              # starting with the input:
   +             #   add
               $ #   the previous result to
    ^2           #   2 to the power of
      ,          #     the length of 
          ``@$   #     the binary digits of the previous result
        >2       #     without the first two digits
       :      $  #     and appending the result so far
```
[Answer]
# [R](https://www.r-project.org), 40 bytes
```
f=\(n){m=log2(print(n))%/%1;f(n+2^m+!m)}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMHOlMzE9Py8xJz4pMy8xKLK-OLUwtLUvORU26WlJWm6Fjc10mxjNPI0q3Ntc_LTjTQKijLzSoB8TVV9VUPrNI08baO4XG3FXM1aiPo9uMzTsLDUhChZsABCAwA)
[Answer]
# x86 32-bit machine code, 14 bytes
```
0F BD C8 E3 03 0F B3 C8 01 D1 0F AB C8 C3
```
[Try it online!](https://tio.run/##nVJdb9owFH22f8UtFZK9mCmEat3I6Mue@9KnSQVFxnHALDiVbbowyl9fdk1ZyVul3gfnfvic4@NYjVZKdZ30W2DwMGC0mpKld6BVK0DLlpINpn/AU7IMLnZEnFE/JbIsz9vKNk79ZUqcDpQPeE6LQobgzHIXdFEw5vTqSbotyzjnYGyAisXVilPxi@fw3BikZTzvro1V9a7U8N2H0jSf13c0btpKYxmnB0qeHNYVGwDGSxQjVePgRLiBGaQ5fq5mMM4wSRJOoRdv2OGtGQjYRPT/3tyOMJIPMo7OcYJHZNA@FM@y9o8L5DiMBWQCJgK@CLgVyIUF9r5@w3yMyThN02Nf2bwqm5NyTKIyQf@v7Di9KJgFIntGhjfmBe2FeJZ3vJAL7nwpFQtiwyP02L@cub2Xam2sBtWUevrms42sAvZYlg0cLmRp9hPZ9jPGdtabldUlqLV0n3jFH9skWfD8CL/XptbA9vFIaftj0v8fwIYGlnt0yecWmdo4xBe2cxZt0GP3V1W1XPlutJ1kuOBjniFS1/8A "C (gcc) ‚Äì Try It Online")
Following the `regparm(2)` calling convention, this takes *n* in EAX and a 0-index in EDX, and returns a number in EAX.
In assembly:
```
f:  bsr ecx, eax    # Set ECX to the highest position of a 1 bit in EAX.
    jecxz s         # Jump if ECX is 0.
    btr eax, ecx    # (Otherwise) Remove that highest 1 bit.
s:  add ecx, edx    # Add the index (in EDX) to ECX.
    bts eax, ecx    # Reinsert a 1 bit into EAX at position ECX.
    ret             # Return.
```
[Answer]
# [Uiua](https://uiua.org), ~~18~~ 14 [bytes](https://www.uiua.org/pad?src=U0JDUyDihpAgK0BcMOKKlwpEZWNvZGUg4oaQIOKHjOKKjy0x4pa9wrEu4o2Y4ouv4oav4oqCwq8x4qe74ouv4qe7LOKHjOKItSjihpjCrzHii68rMjU2KSAtQFwwKzEKJnAg4oqCIjggYml0IGVuY29kaW5nOlx0IiBTQkNTICLih4ziio8tMeKWvcKxLuKNmOKLr-KGr-KKgsKvMeKnu-KLr-Knuyzih4ziiLUo4oaYwq8x4ouvKzI1NikiIOKKgitAXDDih6ExMjkiLiziiLY74oiYwqzCscKv4oy14oia4peL4oyK4oyI4oGFPeKJoDziiaQ-4omlKy3Dl8O34pe_4oG_4oKZ4oan4oal4oig4qe74paz4oeh4oqi4oeM4pmt4ouv4o2J4o2P4o2W4oqa4oqb4oqd4pah4oqU4omF4oqf4oqC4oqP4oqh4oav4oaZ4oaY4oa74per4pa94oyV4oiK4oqXL-KIp1xc4oi14omh4oi64oqe4oqg4o2l4oqV4oqc4oip4oqT4oqD4oqZ4ouF4o2Y4o2c4o2a4qyaJz_ijaPijaQh4o6L4oas4pqCzrfPgM-E4oiefl9bXXt9KCnCr0AkXCLihpB8IyIKJnAg4oqCImRlY29kZWQ6XHQiIERlY29kZSAiwqPCsS0xwrjChy7DjMKlwrPCsMKIMcKfwqXCnyzCo8K_KMK1wogxwqUrMjU2KSIg4oqCK0BcMOKHoTEyOSIuLOKItjviiJjCrMKxwq_ijLXiiJril4vijIrijIjigYU94omgPOKJpD7iiaUrLcOXw7fil7_igb_igpnihqfihqXiiKDip7vilrPih6HiiqLih4zima3ii6_ijYnijY_ijZbiipriipviip3ilqHiipTiiYXiip_iioLiio_iiqHihq_ihpnihpjihrvil6vilr3ijJXiiIriipcv4oinXFziiLXiiaHiiLriip7iiqDijaXiipXiipziiKniipPiioPiipnii4XijZjijZzijZrirJonP-KNo-KNpCHijovihqzimoLOt8-Az4TiiJ5-X1tde30oKcKvQCRcIuKGkHwjIg==)
```
‚ç•(+‚Åø‚à∂2‚Ü•1-1‚ßª‚ãØ.)
```
[Try it!](https://www.uiua.org/pad?src=RiDihpAg4o2lKCvigb_iiLYy4oalMS0x4qe74ouvLikKCkYgMCAxCkYgNSAxCkYgNSA4OQ==)
Returns the nth member of the sequence.
-4 thanks to Dominic van Essen
```
‚ç•(+‚Åø‚à∂2‚Ü•1-1‚ßª‚ãØ.)
‚ç•(           )  # repeat
            .   # duplicate
           ‚ãØ    # convert to bits
          ‚ßª     # length
        -1      # subtract 1
      ‚Ü•1        # max between this and 1 (need this for input of 1)
   ‚Åø‚à∂2          # 2 raised to the result
  +             # add
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 25 21 bytes
```
{2/?[;!2;1,x=1]@2\x}\
```
[Try it online!](https://ngn.codeberg.page/k#eJx9kr1OxDAQhPs8xXFIJNEtuf2x104iBAVN+nQEHTTQUyAkBM/O+Hw1aWxZ3+7OzOZt+tbj/dN8pbPQ1508P+j29bM1zbGRXfmehIwijSSJzMgjiY6kMVEUo2EYnhutoFKgTOJkSh6AZWAOTElYQ2Wtsv+0BBsr65V1PJFkskCOuzHQDDQU1Ek5cuVT5ROJkIxkkRx3E/Aj+Fj4VHipvGg1qHgjc3Koh3Z1Bl2mFgcc4Uv4MsKkyhcKiRIcBCNNQhGNhQ0u2A08FGTlVIvyeC7KwCPwDNwKHgqeCq4FRxrigSFc03iJFo3OEoujFMkYwcGMMGYqjxG1UJAVk1ELWYb2l/ggmkstDgwuLiNMhpixJs9485wUCyhLci8bQlYR5tXVkcO5Cf6EZZLT8nDz2y331O6P27bv2+7qepl4enn9eP/cSd90y/w4r/104J3v0uk4LSgb2qVZp25ob+W0p/3Wt2uz/r4N7aG7lcN1u85L3/wBoCd+9Q==)
-4 bytes - thanks to @coltim
[Answer]
# [Rust](https://www.rust-lang.org), 49 bytes
Input is an integer n as a start value and an integer k for the sequence index. I tried experimenting with `next_power_of_two`, but the name turned out to be way too long.
```
|n:u64,k:u32|1<<n.ilog2()+k|n&!(1<<n.ilog2())|n&1
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TY5BbsIwEEX3PsWESshO02AHhJBDrsCCJbvS1sjCjFGwV7ZP0k0WcChug1NaqZv50p958__3tfcXN9y3CuH0rpEyCMR8OVDQwawk8eQdoPTLRTTWnsO4Mp1Yrz_3h4Iiq7Wxh4ayFrumNBGnxThEIuXs5p16W91F_MGro_TzJmYS_5jX43hP_1tshH_BXUvIh8WLg42E_CEXEpzz7CrbgwaNwOta8FwYAM69RmewoJOXkCQEIfcJaBCJTSrQFSi6ycpYSxJJz4RheOoD)
Explanation and prettier code:
```
// A captureless closure with two integer arguments
// n is the seed number, k is the sequence index
|n: u64, k: u32|
// The following numbers get bit-or'ed together:
       // A one followed by zeroes whose length is the length of the original number plus the parameter k.
       // ilog2 calculates the floored base-2 logarithm.
       // This means 1 shifted by it is equivalent to setting all digits but the most significant one to zero. 
       // Adding k means shifting the most significant one, which is the only thing k is used for in this sequence. 
       1 << n.ilog2() + k
       // The number n, with its most significant one bit set to zero (the replacement part). 
   |   n & !(1 << n.ilog2())
       // A one if the original number's least significant digit contains a one. Only relevant for n=1.
   |   n & 1
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 84 bytes
```
^.+
$*
+`^(1+)\1
$+0
01
1
^(.)(.+)?¬∂(.+)
$1$3$*0$2$#2$*##
0##
0
1|0#
01
+`10
011
%`1
```
[Try it online!](https://tio.run/##HYw9DsIwFIN3XyMvUtJU1XOK@Jk4ARMrqh4DAwsDYuy5coBeLCQd/NmD7e/r9/48qw8mGHUrYiN35p3zzgN8uNtYlylBBiRbAlN8EJIUShBLmGKYUrxupRuEMsugksVlGZyDdoGruj5Ixj4kvLES8WbtC1tpOWPGESewBeJ8AVuNqvoH "Retina 0.8.2 ‚Äì Try It Online") Takes `n` and `k` as input and outputs the `k`th (0-indexed) term of the sequence but link is to test suite for multiple values of `n` that sets `k=0..4` (because larger values would be too slow).
91 bytes to output the first `k` terms:
```
^.+
$*
+`^(1+)\1
$+0
01
1
^(.)(.*)¬∂(.+)
$1$3$*_$2
_
$'¬∂1
O`
1A`
_\b
1
_
0
1
01
+`10
011
%`1
```
[Try it online!](https://tio.run/##FY27DQIxEETzqWNP@CNZO3fiF1IAooGTvSARkBAganMB15hZkqcJZt58nt/X@z6mYIKt70ctGZKQrQbmuBKSFUoQNZQYSopbDyVHCGWR1GRGg@y2TtwMvBja@vB2gzp9mI1/ATEZh/Nq7vQrzzMWHHAEPRCnM@g1quoP "Retina 0.8.2 ‚Äì Try It Online") Takes `n` and `k` as input and outputs the first `k` terms of the sequence but link is to test suite for multiple values of `n` that sets `k=5` (because larger values would be too slow). Explanation:
```
^.+
$*
```
Convert `n` to unary.
```
+`^(1+)\1
$+0
01
1
```
Convert `n` to binary.
```
^(.)(.*)¬∂(.+)
$1$3$*_$2
```
Convert `k` to unary as `_`s and insert it after the first digit of `n`.
```
_
$'¬∂1
O`
1A`
```
Generate all of the first `k` terms.
```
_\b
1
```
Fix the `n=1` error.
```
_
0
```
Change the remaining `_`s to `0`s.
```
1
01
+`10
011
```
Convert to unary.
```
%`1
```
Convert to decimal.
54 bytes with the original intent that the leading `1` participates in the diagonal:
```
.+¬∂
$*_
\d+
$*
+`(1+)\1
$+0
01
1
^.|1
01
+`1[0_]
011
1
```
[Try it online!](https://tio.run/##HYoxDsIwEAT7fYcjHM6KbhNE4BFUlITESFDQUCDKvMsP8MfMxc3saDXf1@/9eZTGxxka3C4nVvaVQ@UhoPHXGEonOcHtF0xPsYVET2knwolCCWLuVm4mkTdd7qb2FqK9RKuQk3mPAUeMoAlxOoNbpKp/ "Retina 0.8.2 ‚Äì Try It Online") Takes `k` and `n` as input and outputs the `k`th (0-indexed) term of the sequence but link is to test suite for multiple values of `n` that sets `k=0..4` (because larger values would be even slower).
70 bytes to output the first `k` terms:
```
.+¬∂
$*_
\d+
$*
+`(1+)\1
$+0
01
1
M!&`_.+
O`
%`^_.|1
01
+`1[0_]
011
%`1
```
[Try it online!](https://tio.run/##FYxBCoNQEEP3uYWgRR34TFps9RDSA1T9U6gLNy6ky57LA3ix73SThEeSbf4u6zsVpU1ojj0FOXbkdcTwEXeIlZRqIHJRKEH02cViEDwNhU0x/PjnYnxpHD3SMZNrb76CfxJX3HDHA/RAtB3oNarqCQ "Retina 0.8.2 ‚Äì Try It Online") Takes `k` and `n` as input and outputs the first `k` terms of the sequence but link is to test suite for multiple values of `n` that sets `k=5` (because larger values would be even slower). Explanation:
```
.+¬∂
$*_
```
Convert `k` to unary as `_`s.
```
\d+
$*
```
Convert `n` to unary.
```
+`(1+)\1
$+0
01
1
```
Convert `n` to binary.
```
M!&`_.+
O`
```
Generate the first `k` terms.
```
%`^_.|1
01
+`1[0_]
011
```
Convert to unary, but the leading `_` makes the next digit `1` while any remaining `_`s are interpreted as `0`s.
```
%`1
```
Convert to decimal.
[Answer]
# [Fortran (GFortran)](https://gcc.gnu.org/fortran/), 73 bytes body, 13 bytes header and footer
```
program x
read*,n;i=2**(31-leadz(n));n=n-i;do;print*,i+n;if(i<2)n=n+1;i=i*2;end do
end
```
Try it online:
[n=1](https://tio.run/##JYtLCoAwDESv0mUb20XrMnqYQj8ENJXgQrx8Dbia4c2bNuSWzKG3v8xLRpd8mmdKzQU8I@0JwK4xHApey84h7xwIy8BLiG/wtKjWLG3J6bRE/RAkrFxMGVNjxg8 "Fortran (GFortran) ‚Äì Try It Online"),
[n=89](https://tio.run/##JYvBCoAgEER/paOuetAuxdbHCGYs1BpLh@jnbaHTDG/e1Ca3ZA57/Uu/pO2Sz@HpsuUCnpHWBGDGGA4Fr2FrkVcOhKXhJcQ3eHKqVUNLsjq5qB@ChBuXobSu0af5Aw "Fortran (GFortran) ‚Äì Try It Online")
Reads `n` from standard input and outputs the corresponding sequence.
Uses `leadz()` to count the leading zeros. Puts the highest 1 into `i` and removes it from `n`. The loop shifts the highest 1 further to the left in each iteration and outputs the sum of `i` and `n` in each cycle. Special handling for `n==1`.
[Answer]
# [Perl 5](https://www.perl.org/).10 -n, 35 bytes
```
$_^=$_-1?3<<(1.4427*log):2while say
```
[Try it online!](https://tio.run/##K0gtyjH9/18lPs5WJV7X0N7YxkbDUM/ExMhcKyc/XdPKqDwjMydVoTix8v9/C8t/@QUlmfl5xf91fctM9QwN/uvmAQA "Perl 5 ‚Äì Try It Online")
Finds the next elem by xor'ing the current n with `3 << log‚ÇÇ(n)` where << is the left shift operator that only cares about the integer part of log‚ÇÇ. Here n=1 is handled as a special case where 1 is xor'ed by 2 to get 3.
```
 89 xor (3 << log2(89)  ) =  89 xor (3<<6) = 153
153 xor (3 << log2(153) ) = 153 xor (3<<7) = 281
281 xor (3 << log2(281) ) = 281 xor (3<<8) = 537
.
.
```
[Answer]
# TI-Basic, 20 bytes
```
While 1
Disp Ans
max(3,Ans+2^int(log(Ans,2
End
```
Takes input in `Ans`. Outputs infinitely with each number on its own line. If not using OS 2.53 MP or higher, replace `log(Ans,2` with `log(Ans)/log(2` for +2 bytes.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~20~~ 19 bytes
```
ÔºÆŒ∏Ôº©‚Å∫Œ∏√óÔº∏¬≤Ôº¨‚çò√∑Œ∏¬≤¬¶¬≤‚äñÔº∏¬≤ÔºÆ
```
[Try it online!](https://tio.run/##TY3BCsIwEETv/YoeN1BBe1J6014KIkH9gZguaaDZtsmmfn5MQdCBN6c3jB6U15MaU@pojnyL7oUeFtEU0ltiuKjAIMcYYKnKp3UYQE7vrNRVeUUyPMBZBXxwtg10xK1dbY@bXYsNkbtF7dEhMfa/9V2RQfh/Fd80KR1PxWGfduv4AQ "Charcoal ‚Äì Try It Online") Takes `n` and `k` as input and outputs the 0-indexed `k`th element but link is to version that outputs the first `k` elements at a cost of 1 byte. Explanation: Port of @Arnauld's JavaScript answer with some inspiration from @DominicvanEssen's Nibbles answer.
```
ÔºÆŒ∏                  Input `n` as a number
       ¬≤            Literal integer `2`
      Ôº∏             Raised to power
           Œ∏        Input `n`
          √∑         Integer divided by
            ¬≤       Literal integer `2`
         ‚çò          Converted to base
              ¬≤     Literal integer `2`
        Ôº¨           Take the length
     √ó              Multiplied by
                 ¬≤  Literal integer `2`
                Ôº∏   Raised to power
                  ÔºÆ Input `k` as a number
               ‚äñ    Decremented
   ‚Å∫                Plus
    Œ∏               Input `n`
  Ôº©                 Cast to string
                    Implicitly print
```
14 bytes with the original intent that the leading `1` participates in the diagonal:
```
ÔºÆŒ∏Ôº©ÔΩúŒ∏Ôº∏¬≤‚Å∫‚äñÔº¨‚Ü®Œ∏¬≤ÔºÆ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05oroCgzr0TDObG4RMMps6Q8szjVHyihoxCQXw5UYQRk5JQWa7ikJhel5qbmlaSmaPik5qWXZGg4JRanghQaaWpq6igEJealp2ogG64JAdb//1tYchka/NctywEA "Charcoal ‚Äì Try It Online") Takes `n` and `k` as input and outputs the 0-indexed `k`th element but link is to version that outputs the first `k` elements at a cost of 1 byte. Explanation:
```
ÔºÆŒ∏              Input `n` as a number
      ¬≤         Literal integer `2`
     Ôº∏          Raised to power
           Œ∏    Input `n`
          ‚Ü®     Converted to base
            ¬≤   Literal integer `2`
         Ôº¨      Take the length
        ‚äñ       Decremented
       ‚Å∫        Plus
             ÔºÆ  Input `k`
   ÔΩú            Bitwise Or
    Œ∏           Input `n`
  Ôº©             Cast to string
                Implicitly print
```
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata), 9 bytes
```
·∂¶{∆Ç2≈ó…î∆É3M
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFTtJJurpKOgpJuDog0NFCKXbC0tCRN12L9w23Lqo81GR2dfnLKsWZj3yXFScnFULkFuw25jLiMucy4zLkMgQxDLgtLLkNDQy5DAwMDiBIA)
A port of [@Leo's Husk answer](https://codegolf.stackexchange.com/a/265891/9288).
```
·∂¶{∆Ç2≈ó…î∆É3M
·∂¶{          Infinite loop and print the result of each iteration:
  ∆Ç             Convert to base 2
   2≈ó…î          Prepend 1/2
      ∆É         Convert back from base 2
       3M       Take the maximum of the result and 3
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Commands)
```
Œªb¬¶T√¨C3M
```
Now that it's been a short while, I'm gonna post my own solution.
Outputs the infinite sequence.
[Try it online](https://tio.run/##yy9OTMpM/f//3O6kQ8tCDq9xNvb9/98QAA) or [verify the first ten terms of all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/c7uTDi0LObzG2dj3f23IocU6/6MNdYx0jHXMdMx1DIEMQx0LSx1DQ0MdQwMDg1gA).
**Explanation:**
```
Œª         # Create a recursive environment,
          # to generate the infinite sequence
          # (which will be lazily output implicitly at the end)
          # Starting with a(0) = (implicit) input
          # And where every following a(n) is calculated as:
          #  Implicitly push the previous term a(n-1)
 b        #  Convert a(n-1) to a binary string
  ¬¶       #  Remove its leading "1"
   T√¨     #  Prepend "10" instead
     C    #  Convert it back from binary to a (base-10) integer
      3M  #  Manually fix a(1) for input=1:
      3   #   Push 3
       M  #   Push a copy of the maximum of the stack
```
[Answer]
# [Uiua](https://uiua.org), 12 [bytes](https://codegolf.stackexchange.com/a/265917/97916)
```
‚ç•(‚Ü•3+‚çú'‚Çô2‚åä.)
‚ç•(+‚Åø‚Ü•1‚åä‚Çô2,2)
```
[Try it online!](https://www.uiua.org/pad?src=ZiDihpAg4o2lKOKGpTMr4o2cJ-KCmTLijIouKQpnIOKGkCDijaUoK-KBv-KGpTHijIrigpkyLDIpCiMgZiDihpAg4o2lKCviioPijZzigpnijIrihqUyKQriioPiiLVmIOKItWcg4oehMTAgODkK4oqD4oi1ZiDiiLVnIOKHoTEwIDEK4oqD4oi1ZiDiiLVnIOKHoTEwIDI=)
```
‚ç•(‚Ü•3+‚çú'‚Çô2‚åä.)    input: repetition, initial number
‚ç•(         )    repeat the successor operation the given number of times:
      ‚çú'‚Çô2‚åä      power of two <= current number
   ‚Ü•3+     .     add to the current number, and maximum with 3 to handle 1
‚ç•(+‚Åø‚Ü•1‚åä‚Çô2,2)
       ‚åä‚Çô2,       floor(log2(current number))
     ‚Ü•1          max with 1 to handle 1
    ‚Åø     2      2 raised to the power of that
   +             add to the current number
```
Could be 10 bytes if there weren't a [bug](https://github.com/uiua-lang/uiua/issues/173) in `‚çú‚Çô`:
```
‚ç•(+‚äÉ‚çú‚Çô‚åä‚Ü•2)
    ‚äÉ    2    call two functions on 2 and the current number:
      ‚çú‚Çô‚åä      power of two <= current number,
         ‚Ü•     max
   +           add the two
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 39 bytes
```
->n,k{r=1;r*=2until n<r*2;n-r/2*2|r<<k}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y5PJ7u6yNbQukjL1qg0ryQzRyHPpkjLyDpPt0jfSMuopsjGJrv2f4GChoGenqGBpl5uYkF1TUVNWrShTkVsLRc2CQMDA5DcfwA "Ruby ‚Äì Try It Online")
]