Learn
Exam

Calculate the Total Sum of All Prime Product Combinations

Difficulty
STARTER

Problem

Given two natural numbers start and end, write a function solution that returns the sum of all product combinations of prime numbers between start and end. A prime number is a natural number greater than 1 that has no divisors other than 1 and itself. For example, 2, 3, 5, 7 are prime numbers, but 4, 6, 8 are not.


Constraints

  • start and end are natural numbers between 1 and 100 inclusive.
  • start is less than or equal to end.
  • If there is 1 or fewer prime numbers between start and end, return 0.

Test Case

Test Case Number start end return
1 2 5 31
2 10 20 1330
3 8 9 0

Explanation for Test Case 1

  • When start = 2 and end = 5, the prime numbers are 2, 3, 5, and the product combinations are 2×3, 2×5, 3×5. The total sum is 6 + 10 + 15 = 31.

Explanation for Test Case 2

  • When start = 10 and end = 20, the prime numbers are 11, 13, 17, 19, and the product combinations are 11×13, 11×17, 11×19, 13×17, 13×19, 17×19. The total sum is 143 + 187 + 209 + 221 + 247 + 323 = 1330.

Explanation for Test Case 3

  • When start = 8 and end = 9, there are no primes (or only 1), so the return value is 0.