Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #54 Sep 06 2023 13:41:12
%S 0,1,2,3,5,6,9,10,11,12,14,15,17,21,24,28,29,30,32,35,36,39,42,44,45,
%T 50,51,54,55,56,57,65,66,71,72,74,75,77,78,80,84,91,95,96,101,105,107,
%U 110,116,117,119,120,122,126,129,131,136,137,141,144,149,150
%N Integers k such that 8*k + 1 is a prime or a square.
%C All odd squares have the form 8*n + 1.
%D G. H. Hardy and E. M. Wright, An Introduction to the Theory of Numbers, 5th ed., Oxford Univ. Press, 1979, theorem 14 and ch. 4.5
%e 8*0 + 1 = 1 = 1^2, so 0 is a term;
%e 8*1 + 1 = 9 = 3^2, so 1 is a term;
%e 8*2 + 1 = 17 = prime(7), so 2 is a term;
%e 8*3 + 1 = 25 = 5^2, so 3 is a term;
%e 8*4 + 1 = 33 is neither prime nor square, so 4 is not a term;
%e 8*5 + 1 = 41 = prime(13), so 5 is a term.
%p q:= k-> (t-> isprime(t) or issqr(t))(8*k+1):
%p select(q, [$0..200])[]; # _Alois P. Heinz_, Feb 25 2020
%t Select[Range[0, 150], PrimeQ[(m = 8*# + 1)] || IntegerQ @ Sqrt[m] &] (* _Amiram Eldar_, Feb 29 2020 *)
%o (Rexx)
%o S = 0 ; U = 1 ; P = 1
%o do N = 1 while length( S ) < 256
%o C = 8 * N + 1
%o do I = U by 2
%o K = I * I ; if K > C then leave I
%o U = I ; if K < C then iterate I
%o S = S || ',' N ; iterate N
%o end I
%o do I = P
%o K = PRIME( I ) ; if K > C then leave I
%o P = I ; if K < C then iterate I
%o S = S || ',' N ; iterate N
%o end I
%o end N
%o say S ; return S
%o (PARI) isok(k) = my(x=8*k+1); isprime(x) || issquare(x); \\ _Michel Marcus_, Feb 27 2020
%Y Union of the triangular numbers A000217 and A005123.
%Y Cf. A000040, A016754 (odd squares).
%K nonn,easy
%O 1,3
%A _Frank Ellermann_, Feb 23 2020