Problem 3: Sum of Primes

Go down

Problem 3: Sum of Primes

Post  Elusive on Sun Jun 05, 2011 8:21 am

What is the sum of a range of primes, specified by order (inclusive)?

Inputs: Start and end numbers, as integers
Outputs: Sum of primes

Example:
Code:

Start: 1st
End: 5th
Sum: 2 + 3 + 5 + 7 + 11 = 28
Code:

Start: 3rd
End: 6th
Sum: 5 + 7 + 11 + 13 = 36
Code:

Start: 125th
End: 3576th
Sum: 691 + 701 + ... + 33377 + 33391 = 56134516

Tips:
  1. Make sure you did Problem 2 properly.


Extension:
Find the product of the primes. Watch for integer overflows!

Elusive
Newbie

Posts : 10
Join date : 2011-06-04

View user profile

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum