Sum of primes in odd positions is prime

Revision as of 13:21, 1 September 2021 by CalmoSoft (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

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.



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