cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A233074 Numbers that are exactly midway between the nearest square and the nearest triangular number.

This page as a plain text file.
%I A233074 #37 Jul 30 2023 08:48:21
%S A233074 2,5,23,32,47,52,65,86,140,161,170,193,203,228,266,312,356,389,403,
%T A233074 438,453,490,545,610,671,716,735,782,802,851,1007,1085,1142,1166,1250,
%U A233074 1311,1503,1598,1667,1696,1767,1870,2098,2177,2210,2291,2325,2408,2528,2792,2883
%N A233074 Numbers that are exactly midway between the nearest square and the nearest triangular number.
%C A233074 Numbers k such that k = (s+t)/2, where s is the square nearest to k, t is the triangular number nearest to k, and s != t. If there are two nearest triangular numbers, either of them is acceptable. - Edited by _Robert Israel_, Oct 07 2019
%C A233074 The sequence of roots of nearest squares begins: 1, 2, 5, 6, 7, 7, 8, 9, 12, 13, 13, 14, 14, 15, 16, 18, 19, 20, 20, 21, 21, ...
%C A233074 The sequence of roots of nearest triangular numbers begins: 2, 3, 6, 7, 9, 10, 11, 13, 16, 17, 18, 19, 20, 21, 23, 24, 26, 27, 28, 29, ...
%C A233074 The sequence of k-t (equals s-k) begins: -1, -1, 2, 4, 2, -3, -1, -5, 4, 8, -1, 3, -7, -3, -10, 12, 5, 11, -3, 3, -12, -6, ...
%H A233074 Robert Israel, <a href="/A233074/b233074.txt">Table of n, a(n) for n = 1..10000</a>
%e A233074 5 is in the sequence because 6 and 4 are the triangular number and square nearest to 5, and 5 = (6+4)/2.
%e A233074 23 is in the sequence because 21 and 25 are the triangular number and square nearest to 23, and 23 = (21+25)/2.
%p A233074 f:= proc(y) local t,x,s,r,R;
%p A233074    t:= y*(y+1)/2;
%p A233074    R:= NULL;
%p A233074    for x from ceil(sqrt(t))-1 to floor(sqrt(t))+1 do
%p A233074      s:= x^2;
%p A233074      if s = t then next
%p A233074      elif s < t then if t-y > s then next fi
%p A233074      else if t+y+1 < s then next fi
%p A233074      fi;
%p A233074      r:= (s+t)/2;
%p A233074      if r::integer then R:= R, r fi
%p A233074    od;
%p A233074    R
%p A233074 end proc:
%p A233074 map(f, [$1..200]; # _Robert Israel_, Oct 06 2019
%t A233074 f[y_] := Module[{t, x, s, r, R = Nothing},
%t A233074   t = y(y+1)/2;
%t A233074   For[x = Ceiling[Sqrt[t]]-1, x <= Floor[Sqrt[t]]+1, x++,
%t A233074     s = x^2;
%t A233074     Which[s == t, Continue[], s < t,
%t A233074     If[t - y > s, Continue[]], True,
%t A233074     If[t + y + 1 < s, Continue[]]];
%t A233074     r = (s + t)/2;
%t A233074     If[IntegerQ[r], R = r]
%t A233074   ];
%t A233074 R];
%t A233074 Map[f, Range[200]] (* _Jean-François Alcover_, Jul 30 2023, after _Robert Israel_ *)
%o A233074 (Java)
%o A233074 import java.math.*;
%o A233074 public class A233074 {
%o A233074   public static void main (String[] args) {
%o A233074     for (long n = 1; ; n++) { // ok for small n
%o A233074       long r2 = (long)Math.sqrt(n), b2 = r2*r2, a2 = (r2+1)*(r2+1);
%o A233074       long t = (long)Math.sqrt(2*n), b3 = t*(t+1)/2, a3 = b3 + t + 1;
%o A233074       if (b3 > n) {
%o A233074         a3 = b3;
%o A233074         b3 = t*(t-1)/2;
%o A233074       }
%o A233074       if ((b2+a3 == n*2 && n - b2 <= a2 - n && a3 - n <= n - b3) ||
%o A233074           (b3+a2 == n*2 && n - b3 <= a3 - n && a2 - n <= n - b2))
%o A233074             System.out.printf("%d, ", n);
%o A233074     }
%o A233074   }
%o A233074 }
%Y A233074 Cf. A000217, A000290, A233075.
%K A233074 nonn,easy
%O A233074 1,1
%A A233074 _Alex Ratushnyak_, Dec 03 2013
%E A233074 Corrected by _Alex Ratushnyak_, Jun 08 2014