SilVer DirectXer:
but..how do u guys discover that all twins prime are subset of (6*k-1,6*k+1), for k is integers?
Let q and q + 2 be twin primes. The number between them is (clearly) q + 1.
Aside from 2, every prime number is odd. So q and q + 2 must both be odd, as both are prime. Hence, q + 1 is even. i.e. q + 1 is divisible by 2.
For any three consecutive integers, exactly one of them is divisible by 3. So either q = 3 and q + 2 = 5 [as 3 | q, q prime => q = 3] or q + 1 is divisible by 3. [And 3 | q + 2 is extraneous since, as before, it would require q + 2 = 3 => q = 1, which isn't prime].
Hence, the twin primes are (3, 5) or (q, q + 2) where q + 1 is divisible by 2 * 3 = 6. The result now follows.
As for the sieve method for generating primes, see an article about Eratosthenes' Sieve, e.g.
http://mathworld.wolfram.com/EratosthenesSieve.html
pavelph:
I'm sorry, but I don't know Pascal very well. But, I think that calling be_prime() in twins() is the cause of the slowness since you'll end up calling it so many times.