27
Since Euclid, we have known that there are infinitely many primes. The argument is by contradiction: If there are only finitely many, let's say \$p_1,p_2,...,p_n\$, then surely \$m:=p_1\cdot p_2\cdot...\cdot p_n+1\$ is not divisible by any of these primes, so its prime factorization must yield a new prime that was not in the list. So the assumption that only finitely primes exist is false.
Now let's assume that \$2\$ is the only prime. The method from above yields \$2+1=3\$ as a new (possible) prime. Applying the method again yields \$2\cdot 3+1=7\$, and then \$2\cdot 3\cdot 7+1=43\$, then \$2\cdot 3\cdot 7\cdot 43+1=13\cdot 139\$, so both \$13\$ and \$139\$ are new primes, etc. In the case where we get a composite number, we just take the least new prime. This results in A000945.
Challenge
Given a prime \$p_1\$ and an integer \$n\$ calculate the \$n\$-th term \$p_n\$ of the sequence defined as follows:
$$p_n := \min(\operatorname{primefactors}(p_1\cdot p_2\cdot ... \cdot p_{n-1} + 1))$$
These sequences are known as Euclid-Mullin-sequences.
Examples
For \$p_1 = 2\$:
1 2
2 3
3 7
4 43
5 13
6 53
7 5
8 6221671
9 38709183810571
For \$p_1 = 5\$ (A051308):
1 5
2 2
3 11
4 3
5 331
6 19
7 199
8 53
9 21888927391
For \$p_1 = 97\$ (A051330)
1 97
2 2
3 3
4 11
5 19
6 7
7 461
8 719
9 5
1
(,0({q:)1+*/)^:
for 15 bytes, returning the sequence up ton
(zero-indexed) – miles – 2019-09-05T09:20:36.520@miles Thank you! – Galen Ivanov – 2019-09-05T09:24:54.033
Very nice. @miles what exactly is happening there grammatically? we put a verb and a conjunction together and get a dyadic verb back. I thought
– Jonah – 2019-09-06T01:43:58.797verb conj
produced an adverb.1@Jonah it's a trick I learned from golfing. I think it's one of the older parsing rules that's still valid – miles – 2019-09-08T22:08:27.233
@miles I just realized it is an adverb (or adnoun). It modifies the noun to its left, which "attaches" to the right of the
^:
, and then that becomes a verb that applies to the right arg. I think that's what's happening grammatically. – Jonah – 2019-09-08T23:45:49.373