Saturday, October 26, 2013



Sum Of Primes.

Difficulty: (2/5)

Write a program that will take an integer as a command line argument and print the sum of all primes less than that number. For example:
% java SumPrimes 10
would sum the primes below 10:
2 + 3 + 5 + 7 = 17
To test your program, calculate the sum of all primes below a million:

Hints: Use the Sieve of Eratosthenes. Also, realize that the sum of all primes below a million is too big to fit in an int.

CS1 Deadline: 11/8/2013
Use: handin cs1113 extra2 SumPrimes.java




No comments:

Post a Comment