Sum of two adjacent numbers are primes: Difference between revisions

Sum of two adjacent numbers are primes en Python
(added AWK)
(Sum of two adjacent numbers are primes en Python)
Line 355:
89712345 + 89712346 = 179424691
</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__":
n = 0
num = 0
 
print('The first 20 pairs of numbers whose sum is prime:')
while True:
n += 1
suma = 2*n+1
if isPrime(suma):
num += 1
if num < 21:
print('{:2}'.format(n), "+", '{:2}'.format(n+1), "=", '{:2}'.format(suma))
else:
break</lang>
{{out}}
<pre>The first 20 pairs of numbers whose sum is prime:
1 + 2 = 3
2 + 3 = 5
3 + 4 = 7
5 + 6 = 11
6 + 7 = 13
8 + 9 = 17
9 + 10 = 19
11 + 12 = 23
14 + 15 = 29
15 + 16 = 31
18 + 19 = 37
20 + 21 = 41
21 + 22 = 43
23 + 24 = 47
26 + 27 = 53
29 + 30 = 59
30 + 31 = 61
33 + 34 = 67
35 + 36 = 71
36 + 37 = 73</pre>
 
 
=={{header|Raku}}==
2,133

edits