Neighbour primes: Difference between revisions

Neighbour primes en Python
(Neighbour primes en Python)
Line 667:
Found 20 such primes: 3, 5, 7, 13, 19, ..., 397, 401, 419, 439, 487
</pre>
 
 
=={{header|Python}}==
<lang python>#!/usr/bin/python
 
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
 
 
if __name__ == '__main__':
print("p q pq+2")
print("-----------------------")
for p in range(2, 499):
if not isPrime(p):
continue
q = p + 1
while not isPrime(q):
q += 1
if not isPrime(2 + p*q):
continue
print(p, "\t", q, "\t", 2+p*q)</lang>
{{out}}
<pre>p q pq+2
-----------------------
3 5 17
5 7 37
7 11 79
13 17 223
19 23 439
67 71 4759
149 151 22501
179 181 32401
229 233 53359
239 241 57601
241 251 60493
269 271 72901
277 281 77839
307 311 95479
313 317 99223
397 401 159199
401 409 164011
419 421 176401
439 443 194479
487 491 239119</pre>
 
 
=={{header|Raku}}==
2,130

edits