7 kyu

Sum of Primes

480 of 513Z-Fikar

Description:

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

You will be given the lower and upper limits: the program will look for any prime number that exists between the lower limit to the upper limit (included).

Your objective is to sum all the primes between the given limits.

  • If the limits are primes, then they are included
  • -100000 <= lower < upper <= 100000
  • If lower is greater than upper, it should return 0

Example

You are given a lower limit of 4 and an upper limit of 20.

So the prime numbers from 4 to 20 will be: 5, 7, 11, 13, 17, 19

and if you add them up, the result will be 72.

sum_primes(4, 20) = 72  # 5 + 7 + 11 + 13 + 17 + 19 = 72

sum_primes(20, 4) = 0  # since lower is greater than upper

sum_primes(2, 7) = 17  # 2 + 3 + 5 + 7 = 17

sum_primes(11, 11) = 11  # it consists of one prime number

sum_primes(60, 60) = 0  # since 60 is not a prime number
Mathematics
Algorithms

Stats:

CreatedApr 28, 2017
PublishedApr 28, 2017
Warriors Trained1119
Total Skips14
Total Code Submissions2601
Total Times Completed513
Python Completions480
Ruby Completions46
Total Stars21
% of votes with a positive feedback rating89% of 170
Total "Very Satisfied" Votes140
Total "Somewhat Satisfied" Votes23
Total "Not Satisfied" Votes7
Total Rank Assessments15
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • Z-Fikar Avatar
  • anter69 Avatar
  • smile67 Avatar
  • lechevalier Avatar
  • ejini战神 Avatar
  • saudiGuy Avatar
Ad