Find squares n where n+1 is prime: Difference between revisions

Added Go
(Add COBOL)
(Added Go)
Line 384:
wend</lang>
{{out}}<pre> 1 4 16 36 100 196 256 400 576 676</pre>
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<lang go>package main
 
import (
"fmt"
"math"
"rcu"
)
 
func main() {
var squares []int
limit := int(math.Sqrt(1000))
i := 1
for i <= limit {
n := i * i
if rcu.IsPrime(n + 1) {
squares = append(squares, n)
}
if i == 1 {
i = 2
} else {
i += 2
}
}
fmt.Println("There are", len(squares), "square numbers 'n' where 'n+1' is prime, viz:")
fmt.Println(squares)
}</lang>
 
{{out}}
<pre>
There are 10 square numbers 'n' where 'n+1' is prime, viz:
[1 4 16 36 100 196 256 400 576 676]
</pre>
 
=={{header|GW-BASIC}}==
9,482

edits