User blog comment:VoidSansXD/My attempt at not creating a recursive function/@comment-37246647-20190209234852/@comment-37246647-20190210035502

Here's how I derived it:

Basically, after any n, there will come a prime number, because both sets are infinite. The task is to find the first prime after n. Take the difference of p-n, where p is the prime. Because the last non-prime and the prime are going to repeat, we'll subtract 2 from the difference. the rest of the total is how many times the last non-prime and the prime repeat, which is simply 2c (c being the last composite number before the prime). Add the difference of p-n to 2c, and you have your answer. For J(n) where n is the prime, the answer is simply 2c-1, since you had no steps before the prime.