Everyone knows the only even prime number is
2. Ho-hum. But, there are certain even numbers
n where, when concatenated with
n-1, they become a prime number.
1 isn't in the list, because
10 isn't prime. Similarly with
4 works because
43 is prime, so it's the first number in the sequence
a(1) = 4. The next number that works (neither
87) work) is
109 is prime, so
a(2) = 10. Then we skip a bunch more until
2221 is prime, so
a(3) = 22. And so on.
Obviously all terms in this sequence are even, because any odd number
n when concatenated with
n-1 becomes even (like
3 turns into
32), which will never be prime.
This is sequence A054211 on OEIS.
Given an input number
n that fits somewhere into this sequence (i.e.,
n concatenated with
n-1 is prime), output its position in this sequence. You can choose either 0- or 1-indexed, but please state which in your submission.
- The input and output can be assumed to fit in your language's native integer type.
- The input and output can be given in any convenient format.
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- If possible, please include a link to an online testing environment so other people can try out your code!
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
The below examples are 1-indexed.
n = 4 1 n = 100 11 n = 420 51