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

From Rosetta Code
Content added Content deleted
(Created page with "{{Draft task}} ;Task:Let '''p(n)''' be a sequence of prime numbers. <br>Consider the '''p(1),p(3),p(5), ... ,p(i)''' for each '''i <= n''' <br>Let '''sum''' be summarize of t...")
 
No edit summary
Line 1: Line 1:
{{Draft task}}
{{Draft task}}


;Task:
;Task: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 '''i <= n'''
<br>Consider the '''p(1),p(3),p(5), ... ,p(i)''' for each '''i <= n'''
<br>Let '''sum''' be summarize of these primes.
<br>Let '''sum''' be summarize of these primes.

Revision as of 13:22, 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 i <= n
Let sum be summarize of these primes.
If sum is prime then print p(i) and sum, where n < 1,000



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...