A233074 Numbers that are exactly midway between the nearest square and the nearest triangular number.
2, 5, 23, 32, 47, 52, 65, 86, 140, 161, 170, 193, 203, 228, 266, 312, 356, 389, 403, 438, 453, 490, 545, 610, 671, 716, 735, 782, 802, 851, 1007, 1085, 1142, 1166, 1250, 1311, 1503, 1598, 1667, 1696, 1767, 1870, 2098, 2177, 2210, 2291, 2325, 2408, 2528, 2792, 2883
Offset: 1
Examples
5 is in the sequence because 6 and 4 are the triangular number and square nearest to 5, and 5 = (6+4)/2. 23 is in the sequence because 21 and 25 are the triangular number and square nearest to 23, and 23 = (21+25)/2.
Links
- Robert Israel, Table of n, a(n) for n = 1..10000
Programs
-
Java
import java.math.*; public class A233074 { public static void main (String[] args) { for (long n = 1; ; n++) { // ok for small n long r2 = (long)Math.sqrt(n), b2 = r2*r2, a2 = (r2+1)*(r2+1); long t = (long)Math.sqrt(2*n), b3 = t*(t+1)/2, a3 = b3 + t + 1; if (b3 > n) { a3 = b3; b3 = t*(t-1)/2; } if ((b2+a3 == n*2 && n - b2 <= a2 - n && a3 - n <= n - b3) || (b3+a2 == n*2 && n - b3 <= a3 - n && a2 - n <= n - b2)) System.out.printf("%d, ", n); } } }
-
Maple
f:= proc(y) local t,x,s,r,R; t:= y*(y+1)/2; R:= NULL; for x from ceil(sqrt(t))-1 to floor(sqrt(t))+1 do s:= x^2; if s = t then next elif s < t then if t-y > s then next fi else if t+y+1 < s then next fi fi; r:= (s+t)/2; if r::integer then R:= R, r fi od; R end proc: map(f, [$1..200]; # Robert Israel, Oct 06 2019
-
Mathematica
f[y_] := Module[{t, x, s, r, R = Nothing}, t = y(y+1)/2; For[x = Ceiling[Sqrt[t]]-1, x <= Floor[Sqrt[t]]+1, x++, s = x^2; Which[s == t, Continue[], s < t, If[t - y > s, Continue[]], True, If[t + y + 1 < s, Continue[]]]; r = (s + t)/2; If[IntegerQ[r], R = r] ]; R]; Map[f, Range[200]] (* Jean-François Alcover, Jul 30 2023, after Robert Israel *)
Extensions
Corrected by Alex Ratushnyak, Jun 08 2014
Comments