Special neighbor primes: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
(Special neighbor primes en Python) |
||
Line 653: | Line 653: | ||
Found 103,611 special neighbour primes < 10,000,000 |
Found 103,611 special neighbour primes < 10,000,000 |
||
</pre> |
</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 |
|||
def nextPrime(n): |
|||
#finds the next prime after n |
|||
if n == 0: |
|||
return 2 |
|||
if n < 3: |
|||
return n + 1 |
|||
q = n + 2 |
|||
while not isPrime(q): |
|||
q += 2 |
|||
return q |
|||
if __name__ == "__main__": |
|||
for p1 in range(3,100,2): |
|||
p2 = nextPrime(p1) |
|||
if isPrime(p1) and p2 < 100 and isPrime(p1 + p2 - 1): |
|||
print(p1,'\t', p2,'\t', p1 + p2 - 1)</lang> |
|||
{{out}} |
|||
<pre>3 5 7 |
|||
5 7 11 |
|||
7 11 17 |
|||
11 13 23 |
|||
13 17 29 |
|||
19 23 41 |
|||
29 31 59 |
|||
31 37 67 |
|||
41 43 83 |
|||
43 47 89 |
|||
61 67 127 |
|||
67 71 137 |
|||
73 79 151</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |