In the loop $i$ is equal to $30k+7$, where $k$ is a non-negative integer. Let's consider what values can't be prime. I'll list the offsets and remove them as they're eliminated.
$$0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29$$
We start with $7$, which is odd. Adding another odd number would give us an even number, which is divisible by $2$. Eliminate those.
$$0,2,4,6,8,10,12,14,16,18,20,22,24,26,28$$
We're adding multiples of $30$, which are divisible by $3$. The last digit is $7$. Adding $2$ would make it $9$, making the whole number divisible by $3$. So $2$ gets skipped, so well as $2+3k$. Eliminate those.
$$0,4,6,10,12,16,18,22,24,28$$
Same logic for $5$. Since the last digit is $7$ without an offset, then adding $3,8,13$, etc, would make it a multiple of $5$. Eliminate those.
$$0,4,6,10,12,16,22,24$$
And you're left with the numbers that are checked. We increment by $30$ since $2\cdot3\cdot5=30$, and we checked those at the very beginning. Adding $30$ produces the same pattern of divisibility by those numbers at the same offsets. So from then on we just need to dodge those offsets.
Best Answer
GIMPS just considers Mersenne primes, so there is a fixed formula.
However if you are looking for a "biggish" prime, say 1024-bits well suited for cryptography, that is a prime $p$ with $2^{1024} < p < 2^{1025}$. Out of the $2^{1024}$ numbers in the range, approximately $$\frac{2^{1025}}{\log 2^{1025}} - \frac{2^{1024}}{\log 2^{1024}}$$ are prime. So the fraction which are prime is $$\frac{2}{\log 2^{1025}} - \frac{1}{\log 2^{1024}}= \frac{2}{1025\log 2} - \frac{1}{1024\log 2} = 0.001406$$ Since you can test as many as you want, that's not such bad odds.