Jump to content

Prime numbers p for which the sum of primes less than or equal to p is prime: Difference between revisions

no edit summary
imported>Chinhouse
No edit summary
Line 396:
953
</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
isPrime = function(n)
if n <= 3 then return n > 1
if n % 2 == 0 or n % 3 == 0 then return false
i = 5
while i ^ 2 <= n
if n % i == 0 or n % (i + 2) == 0 then return false
i += 6
end while
return true
end function
 
primes = []
sum = 0
for n in range(2, 1000)
if isPrime(n) then
sum += n
if isPrime(sum) then primes.push(n)
end if
end for
print primes.len + " found: " + primes
</syntaxhighlight>
 
 
{{out}}
<pre>
21 found: [2, 3, 7, 13, 37, 43, 281, 311, 503, 541, 557, 593, 619, 673, 683, 733, 743, 839, 881, 929, 953</pre>
 
=={{header|Nim}}==
Line 785 ⟶ 815:
");
]</syntaxhighlight>
 
{{out}}
<pre>2 3 7 13 37 43 281 311 503 541
<pre>
2 3 7 13 37 43 281 311 503 541
557 593 619 673 683 733 743 839 881 929
953
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.