Sum of two adjacent numbers are primes: Difference between revisions

→‎{{header|Go}}: Recoded to do extra credit.
(Added Go)
(→‎{{header|Go}}: Recoded to do extra credit.)
Line 456:
import (
"fmt"
"math"
"rcu"
)
 
func main() {
limit := int(math.Log(1e7) * 1e7 * 1.2) // should be more than enough
primes := rcu.Primes(limit)
fmt.Println("The first 20 pairs of natural numbers whose sum is prime are:")
countfor i := 01; i <= 20; i++ {
for n := 1; countp < 20; n++:= {primes[i]
ifhp rcu.IsPrime(2*n:= +p 1)/ {2
fmt.Printf("%2d + %2d = %2d\n", nhp, nhp+1, 2*n+1p)
count++
}
}
fmt.Println("\nThe 10 millionth such pair is:")
p := primes[1e7]
hp := p / }2
fmt.Printf("%2d + %2d = %2d\n", hp, hp+1, p)
}</lang>
 
Line 493 ⟶ 498:
35 + 36 = 71
36 + 37 = 73
 
The 10 millionth such pair is:
89712345 + 89712346 = 179424691
</pre>
 
9,485

edits