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

Created Nim solution.
No edit summary
(Created Nim solution.)
Line 658:
576
676</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="Nim">import std/strutils
 
func isPrime(n: Positive): bool =
if n < 2: return false
if (n and 1) == 0: return n == 2
var d = 3
while d * d <= n:
if n mod d == 0:
return false
inc d, 2
result = true
 
var list = @[1]
var n = 2
var n2 = 4
while n2 < 1000:
if isPrime(n2 + 1):
list.add n2
inc n, 2
n2 = n * n
 
echo list.join(" ")
</syntaxhighlight>
 
{{out}}
<pre>1 4 16 36 100 196 256 400 576 676
</pre>
 
=={{header|OCaml}}==
256

edits