TITLE: Pascal Triangle and Prime Numbers
QUESTION [18 upvotes]: Back in the days when I was in high-school I developed a big interest about number theory specifically prime numbers and prefect numbers, I used to stay awake all night long with a bunch of sketch papers trying to come up with a formula to generate / test prime numbers. I discovered a lot of things by my own like $p(p + 1)/2$ is a perfect number when p is a Mersenne prime.
I was so obsessed back then that I used to make mental calculations when I was asleep, I remember one day waking up really excited because I had discovered that $2^p - 2  = 0 \pmod p$ when $p$ is a prime, only to discover a few weeks later that Pierre de Fermat had a similar idea but, unfortunately it didn't work for pseudoprimes. I was very disappointed back then and I started playing with the Pascal triangle.
Blaise Pascal, Marin Mersenne and Pierre de Fermat were contemporaneous and shared thoughts with letters, in fact if you think a bit both the Mersenne prime formula and the Fermat primality test seem to be closely related with the rows of the Pascal triangle (the sum of all numbers in row $n$ is $2^n$ where the first and last numbers are $1$, hence the $-1$ in the Mersenne formula and $-1$ or $-2$ in the primality tests).
I coded a Pascal Triangle generator with PHP and HTML that highlighted all the numbers that were multiples of a specific number and the results amazed me, and until this day I don't know why this happens and I would very much like to know why. Instead of trying to explain, I'll post here the images.
Composite Example:

Prime Example:

I think the difference [between the prime and composite cases] is obvious, but if you're confused just say so and I'll try to go into it a bit more...
Can anyone explain me why does this happens?

REPLY [4 votes]: I also wanted to give a very short answer. Let $p$ be a prime number. It is easy to see that the binomial coefficient $\left(p\atop n\right)$ is divisible by $p$ for $1\le n\le p-1$. So the $p$-th line looks like $1,0,0,\ldots,0,1$ mod $p$. Then by the recursive definition of the Pascal triangle a new triangle starts at the left and at the right (until they meet in the mid somewhere). And this process goes on and on. Probably the line $\left(p^2\atop *\right)$ is also a line with this property, etc. 
This explains the recursive nature of this phenomenon.