# The Primitive and Basic Numbers

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).

## I/O:

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 , 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.

• I find "turn it into base 3" misleading. That sounds like I should convert either 4 or 100 to base 3 which is either 11 or 10201. What you seem to intend is that the representation from the previous base should now be treated as digits in the next base. Dec 20, 2016 at 9:26
• What are we supposed to do? Create a program/function takes takes input and gives the nth PB term? Or are we supposed to generate all terms below 2^31-1? Dec 20, 2016 at 9:28
• Sorry for the misleading thing: your program must be able to handle terms that are up to 2^31-1. It's meant to take an input n and return the output PB(n). Dec 20, 2016 at 9:29
• I just hope all these comments get me the "Blue in the Face" hat Dec 20, 2016 at 9:30
• I didn't understand the task the first time I read it, so I rephrased it in an attempt to make it clearer. Please feel free to roll back any changes you disagree with. Dec 21, 2016 at 7:01

# Ruby, 126 bytes

require("prime")
->n{o=4
(2..n).map{|i|j=i+1
r=[]
(r.unshift o%i;o/=i)while o>0
o=r.inject{|s,k|s*j+k}+Prime.first(j)[-1]}
o}


# Jelly, 13 bytes

’ß1¹?bḅ‘+‘ÆN$ Try it online! ### How it works ’ß1¹?bḅ‘+‘ÆN$  Main link. Argument: n

’              Decrement; yield n-1.
¹?          If n-1 is non-zero:
ß               Recursively call the main link with argument n-1.
Else:
1              Yield 1.
b         Convert the result to base n.
ḅ‘       Convert from base n+1 to integer.