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
startandendare natural numbers between 1 and 100 inclusive.startis less than or equal toend.- If there is 1 or fewer prime numbers between
startandend, return0.
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 = 2andend = 5, the prime numbers are2, 3, 5, and the product combinations are2×3,2×5,3×5. The total sum is6 + 10 + 15 = 31.
Explanation for Test Case 2
- When
start = 10andend = 20, the prime numbers are11, 13, 17, 19, and the product combinations are11×13,11×17,11×19,13×17,13×19,17×19. The total sum is143 + 187 + 209 + 221 + 247 + 323 = 1330.
Explanation for Test Case 3
- When
start = 8andend = 9, there are no primes (or only 1), so the return value is0.