Prime numbers p for which the sum of primes less than or equal to p is prime: Difference between revisions
Content added Content deleted
(Created page with "{{Draft task}} ;Task:Find prime numbers '''p''' which sum of prime numbers less or equal to '''p''' is prime, where '''p < 1000''' <br><br> =={{header|Ring}}== <lang ring>...") |
|||
Line 4: | Line 4: | ||
<br><br> |
<br><br> |
||
=={{header|Phix}}== |
|||
<!--<lang Phix>(phixonline)--> |
|||
<span style="color: #008080;">function</span> <span style="color: #000000;">sump</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]))</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
|||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">sump</span><span style="color: #0000FF;">)</span> |
|||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d found: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span> |
|||
<!--</lang>--> |
|||
{{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|Ring}}== |
=={{header|Ring}}== |
Revision as of 16:38, 7 July 2021
Prime numbers p for which the sum of primes less than or equal to p is prime is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- Task
- Find prime numbers p which sum of prime numbers less or equal to p is prime, where p < 1000
Phix
function sump(integer p, i, sequence s) return is_prime(sum(s[1..i])) end function sequence res = filter(get_primes_le(1000),sump) printf(1,"%d found: %V\n",{length(res),res})
- Output:
21 found: {2,3,7,13,37,43,281,311,503,541,557,593,619,673,683,733,743,839,881,929,953}
Ring
<lang ring> load "stdlib.ring" see "working..." + nl see "Prime numbers p which sum of prime numbers less or equal to p is prime:" + nl
row = 0 sum = 0 limit = 1000
for n = 1 to limit
if isprime(n) sum = sum + n if isprime(sum) see "" + n + " " row = row + 1 if row%5 = 0 see nl ok ok ok
next
see nl + "Found " + row + " numbers" + nl see "done..." + nl </lang>
- Output:
working... Prime numbers p which sum of prime numbers less or equal to p is prime: 2 3 7 13 37 43 281 311 503 541 557 593 619 673 683 733 743 839 881 929 953 Found 21 numbers done...