Sum of primes in odd positions is prime: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
No edit summary
Line 3: Line 3:
;Task:
;Task:
<br>Let '''p(n)''' be a sequence of prime numbers.
<br>Let '''p(n)''' be a sequence of prime numbers.
<br>Consider the '''p(1),p(3),p(5), ... ,p(i)''' for each '''p(i) < 1,000n''' and ''i''' is odd.
<br>Consider the '''p(1),p(3),p(5), ... ,p(i)''', for each '''p(i) < 1,000n''' and '''i''' is odd.
<br>Let '''sum''' be summarize of these primes.
<br>Let '''sum''' be summarize of these primes.
<br>If '''sum''' is prime then print '''p(i)''' and '''sum'''
<br>If '''sum''' is prime then print '''p(i)''' and '''sum'''

Revision as of 13:46, 1 September 2021

Sum of primes in odd positions 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


Let p(n) be a sequence of prime numbers.
Consider the p(1),p(3),p(5), ... ,p(i), for each p(i) < 1,000n and i is odd.
Let sum be summarize of these primes.
If sum is prime then print p(i) and sum



Ring

<lang ring> load "stdlib.ring" see "working..." + nl see "p" + " sum" + nl

nr = 0 sum = 0 limit = 1000

for n = 2 to limit

   if isprime(n)
      nr++
      if nr%2 = 1
         sum += n
         if isprime(sum)
            see "" + n + " " + sum + nl
         ok
      ok
   ok

next

see "done..." + nl </lang>

Output:
working...
p  sum
2 2
5 7
31 89
103 659
149 1181
331 5021
467 9923
499 10909
523 11941
653 17959
823 26879
done...