Definitions
The common methods to generate consecutive composites are
$$\overbrace{(n+1)! + 2, \ (n+1)! + 3, \ \ldots, \ (n+1)! + (n+1)}^{\text{n composites}}$$
$$\overbrace{n!+2,n!+3,...,n!+n}^{\text{n-1 composites}}$$
$$\overbrace{n\#+2,n\#+3,…n\#+n}^{\text{n-1 composites (Primorials)}}$$
A less common method involves the Chinese Remainder Theorem (CRT).
For example, define a list of \$n\$ pairwise coprimes \$p_1, p_2, \ldots, p_n\$.
A set of integers can also be called coprime if its elements share no common positive factor except 1. A stronger condition on a set of integers is pairwise coprime, which means that \$a\$ and \$b\$ are coprime for every pair \$(a, b)\$ of different integers in the set. The set \$\{2, 3, 4\}\$ is coprime, but it is not pairwise coprime since 2 and 4 are not relatively prime.
Create a set of \$n\$ congruences
\begin{align*} x + 1 &\equiv 0 \pmod{p_1} \\ x + 2 &\equiv 0 \pmod{p_2} \\ &\vdots \\ x + n &\equiv 0 \pmod{p_n} \end{align*}
By CRT, there exists a unique solution \$x\$ which satisfies this sequence of \$n\$ consecutive composite numbers:
$$x + 1, x + 2, \ldots, x + n$$
A composite number is a positive integer that can be formed by multiplying two smaller positive integers. Equivalently, it is a positive integer that has at least one divisor other than 1 and itself.
Challenge
Given pairwise coprime inputs, find the smallest range of consecutive composite numbers.
Input
A list of \$n\$ pairwise coprimes.
Output
A sequence of \$n\$ consecutive composite numbers.
Test Cases
These cases were derived from this test.
n | pairwise coprimes | consecutive composites |
---|---|---|
2 | 2, 3 | 8,9 |
3 | 7, 11, 23 | 1792, 1793, 1794 |
4 | 2, 3, 5, 7 | 158, 159, 160, 161 |
5 | 3, 7, 10, 13, 23 | 47928, 47929, 47930, 47931, 47932 |
Added a JavaScript (V8) tool to validate if the input numbers are pairwise coprime.
8,9
? According to the definition in the challenge I believe it should be8,9
again, but your code and some of the answers are returning80,81
instead \$\endgroup\$8,9
. Thanks for catching that edge case. \$\endgroup\$