Your task is to generate the "Primitive and Basic" numbers, which are made like so:
Start with 110. Take the digits of its base-1 representation (110 = 11) and interpret them as base-2 digits. This gives 12 = 110. Now, add the second prime number – 310 – to the result. This will give you 410, which is our first "Primitive and Basic" (PB) number, or PB(1) (you can now see where I got the name from).
Next, take 410 = 1002 and interpret the digits of its base-2 representation as base-3 digits. This gives 1003 = 910. Add the third prime number – 510 – to the result, which gives 1410. That's the second PB number, or PB(2).
You can see where this is going: take 1410 = 1123 and interpret the digits of its base-3 representation as base-4 digits. This gives 1124 = 2210. Add the fourth prime number – 710 – to the result, which gives 2910.
This continues on and on forever.
In general, PB(n) is equal to PB(n-1), converted to base n and from base n+1 to integer, plus the (n+1)th prime.
The first few terms of this sequence are:
4, 14, 29, 52, 87, 132, 185...
You must write a function or program that creates these numbers. It must take a positive integer n as input, and return PB(n).
1 -> 4 5 -> 87
Rules and specs:
- Your program must be able to handle all PB numbers below 231-1.
- Standard loopholes apply.
- The input may be 0-indexed or 1-indexed, whichever you prefer.
- The input is guaranteed to be a valid index.
- The output must be in base 10.
This is code-golf, so shortest code in bytes wins!
Unfortunately, there isn't an OEIS sequence for this. You can propose to OEIS to add this sequence in if you want.