%I #41 Jan 27 2021 10:31:18
%S 1,3,5,7,11,13,17,19,23,37,41,43,53,59,61,67,71,73,79,97,113,131,163,
%T 179,181,211,223,239,241,293,307,337,367,373,397,409,439,487,491,499,
%U 631,673,691,719,733,739,769,853,881,883,907,919,991
%N a(1)=1 and for n>1, a(n) equals the smallest prime greater than a(n-1) of the form a(i)*a(j)+2 for some i, j < n.
%C Is this sequence finite?
%C For n>1, a(n)-2 is prime or semiprime.
%C If a(n) is the lesser of a twin prime pair, then a(n+1) = a(n)+2 (= a(1)*a(n)+2). - _M. F. Hasler_, Feb 11 2012
%C There are exactly 3478486 terms < 10^18 with a(3478486) = 999999462621744733. - _Terentyev Oleg_, Mar 09 2012
%H M. F. Hasler, <a href="/A204142/b204142.txt">Table of n, a(n) for n = 1..20000</a>
%H <a href="http://dxdy.ru/topic53841.html">Discussion at forum dxdy.ru</a> (in Russian)
%e a(2) = a(1)^2+2, a(3) = a(1)*a(2)+2, a(4) = a(1)*a(3)+2, a(5) = a(2)^2+2, a(6)=a(1)*a(5)+2, a(7) = a(1)*a(5)+2, a(8) = a(2)*a(3)+2, ...
%e a(16027) = 14228123711 is the lesser of a twin prime pair, it is followed by the greater twin prime, a(16028) = 14228123713.
%t a = {1}; s = {}; While[s = Union[s, Select[a*a[[-1]] + 2, PrimeQ]]; s != {} && Length[a] < 100, AppendTo[a, s[[1]]]; s = Rest[s]]; a (* _T. D. Noe_, Mar 12 2012 *)
%o (PARI) a=Set(p=1); for(n=1,999, until(bigomega(p-2)<3 & !setminus(Set(factor(p-2)[,1]~),a), p=nextprime(p+2)); a=setunion(a,Set(p))); vecsort(eval(a)) \\ _M. F. Hasler_, Feb 10 2012
%o (PARI) {a=[r=1]; for(n=1, 9999, while(a[r]^2+2<=a[n], r++); m=0; s=r; for(i=r, n, while(s>1&&a[s-1]*a[i]+2>a[n], s--); for( j=s, i, m & a[j]*a[i]+2>m & break; isprime(a[j]*a[i]+2) & m=a[j]*a[i]+2 )); a=concat(a, m))} \\ _M. F. Hasler_, Feb 10 2012
%K nonn
%O 1,2
%A _Max Alekseyev_, Jan 16 2012