Fun with Primes FYI this is my first post on Math.stackexchange
So, I'm taking Discrete Math in University and I've just been introduced to the Fundamental Theorem of Arithmetic. Now that I'm done my studies for the day I've been playing around with Primes trying to spot interesting patterns. One thing I noticed is that every prime number is always $2$ or $(k2^n+ 2)$ positions from the next prime. I don't think this is terribly profound because primes are by definition not even, so a prime is more likely to be odd, unless that odd number happens to be divisible by 3, or 5, or some other prime. But, I kept playing with it and I used an old C++ program to calculate the spaces between primes ranging from $1$ to $10000$. And I got this:
And image of the console
The Code for this is here, in C++:
#include <iostream>
#include <vector>
using namespace std;
bool primeEval;
vector<int> prime;
int numberOfPrimes = 0;
int prev;

void PrimeSpace() {
    cout << " ";
}
int main() {
    for (int i = 2; i < 10000; i++) {
        for (int j = 2; j <= 5000; j++) {
            int answer = i % j;
            if (i == j) {
                primeEval = false;
                continue;
            }
            if (answer == 0) {
                primeEval = false;
                break;
            }
            primeEval = true;
        }
        if (primeEval) {
            prime.push_back(i);
            if (i > 3) {
                int space = prime[numberOfPrimes] - prime[numberOfPrimes-1];
                for (int i = 0; i < space; i++) {
                    PrimeSpace();
                }
                cout << space << endl;
            }           
            numberOfPrimes++;
        }
    }
}

So my question is, why is every prime $2, 2^n$ or $(k2^n+2)$ from the next prime and does it mean anything interesting?
 A: This appears to be a law of small numbers situation, where a few observations reveal a pattern that does not actually hold up in general. In fact, the pattern is already shown to be broken by the code output shown, as 14 cannot be represented in any of the ways described.
What is known is that for primes $p>3$, $p$ must be congruent to $1$ or $5 \text{ modulo }6$. This means that if you take the differences between consecutive primes, they must be congruent to $0$, $2$, or $4 \text{ mod }6$. Furthermore, differences not congruent to $0$ must take you from $1$ to $5$ (diff. $4 \text{ mod }6$), or vice versa (diff. $2 \text{ mod }6$). Thus the differences will alternate between $2$ and $4 \text{ mod }6$, possibly seperated by differences of $0 \text{ mod }6$
A: $3-2=1$ is an odd difference between primes.
Your formula when $n=1$ is $2(k+2)$. As $k$ varies over all natural numbers, that varies over all even numbers greater than $2$, so you are effectively just noticing that prime differences are even when the primes are greater than 2.
Polignac’s conjecture says that every even number is a prime jump gap infinitely many times. The density of primes and their corresponding gaps can be estimated using the prime number theorem.
