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.

A232178 Least k>=0 such that triangular(n) + k^2 is a square, or -1 if no such k exists.

Original entry on oeis.org

0, 0, 1, -1, -1, 1, 2, 6, 0, 2, 3, -1, -1, 3, 4, 1, 15, 4, 5, -1, -1, 5, 6, 20, 10, 6, 7, -1, -1, 7, 8, 27, 1, 8, 9, -1, -1, 9, 10, 2, 36, 10, 11, -1, -1, 11, 12, 41, 7, 0, 13, -1, -1, 13, 6, 24, 2, 14, 15, -1, -1, 15, 16, 3, 6, 8, 17, -1, -1, 17, 18, 62, 64, 18, 19
Offset: 0

Views

Author

Alex Ratushnyak, Nov 20 2013

Keywords

Comments

Triangular(n) = n*(n+1)/2.

Examples

			a(7) = 6 because the least k such that triangular(n) + k^2 is a square is k=6: 7*(7+1)/2 + 6^2 = 28+36 = 64 = 8^2.
		

Crossrefs

Cf. A082183 (least k>0 such that triangular(n) + triangular(k) is a triangular number).
Cf. A232177 (least k>0 such that triangular(n) + triangular(k) is a square).
Cf. A232176 (least k>0 such that n^2 + triangular(k) is a square).
Cf. A232179 (least k>=0 such that n^2 + triangular(k) is a triangular number).
Cf. A101157 (least k>0 such that triangular(n) + k^2 is a triangular number).

Programs

  • Mathematica
    Join[{0}, Table[k = 0; While[k < n && ! IntegerQ[Sqrt[n*(n + 1)/2 + k^2]], k++]; If[k == n, k = -1]; k, {n, 100}]] (* T. D. Noe, Nov 21 2013 *)
  • Python
    from _future_ import division
    from sympy import divisors
    def A232178(n):
        if n == 0:
            return 0
        t = n*(n+1)//2
        ds = divisors(t)
        l, m = divmod(len(ds),2)
        if m:
            return 0
        for i in range(l-1,-1,-1):
            x = ds[i]
            y = t//x
            a, b = divmod(y-x,2)
            if not b:
                return a
        return -1 # Chai Wah Wu, Sep 12 2017