Sum the Next Two Prime-Product Terms
Problem statement
A sequence begins 2, 5, 6, 11, 30, 37, 210, 221, 2310, 2323, 30030, 30047, ....
For this exercise, assume p[j] is the jth prime number, starting with p[1] = 2, and P[j] is the product of the first j primes. Pair j contains the two consecutive terms P[j] and P[j] + p[j+1].
You are given completedPairs, the number of complete pairs already present. Return the sum of the next two terms, which together form pair completedPairs + 1.
For this exercise, assume the pair count generalizes the six complete pairs displayed above. Complete sumNextPrimorialPair(completedPairs) and return the exact sum as a signed 64-bit integer.
Function
sumNextPrimorialPair(completedPairs: int) → longExamples
Example 1
completedPairs = 6return = 1021039The first six complete pairs end with (30030, 30047). The next prime product is 30030 * 17 = 510510, and its partner is 510510 + 19 = 510529. Their sum is 1021039.
Example 2
completedPairs = 1return = 17The first pair is (2, 5). The next pair is (2 * 3, 2 * 3 + 5) = (6, 11), so the sum is 17.
Example 3
completedPairs = 14return = 1229779565176982873The next pair uses the product of the first 15 primes, 614889782588491410, and the following prime, 53. Its two terms sum to 1229779565176982873. Exact 64-bit arithmetic is required.
Constraints
- For this exercise, assume
1 <= completedPairs <= 14. - Pairs are numbered from
1and use consecutive primes in increasing order. - The largest possible sum is
1229779565176982873, which fits a signed 64-bit integer.