NSBCoding
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Problem 3: Sum of Primes

Go down

Problem 3: Sum of Primes Empty Problem 3: Sum of Primes

Post  Elusive 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

Back to top Go down

Back to top

- Similar topics

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