[seqfan] Re: (no subject)

franktaw at netscape.net franktaw at netscape.net
Mon Nov 9 17:22:27 CET 2009

There was a discussion here just a couple of weeks ago about what 
numbers can be added to a triangular number to get a square.

Specifically, for the first few values, look at the numbers mod 9.  The 
triangular numbers mod 9 are 0, 1, 3, and 6; the squares mod 9 are 0, 
1, 4, and 7.  If you look at the differences, you will see that 2 and 5 
cannot be obtained.  This takes care of 2, 5, 11, 16, 20, 25, ....

In general, to determine if a number k can be represented in this way, 
factor 8k-1.  If any prime p == 3 or 5 (mod 8) appears as a factor an 
odd number of times (i.e., p, p^3, p^5, ...; but p^2, p^4, p^6, ... are 
OK), k cannot be represented as the difference of a square and a 
triangular number.  Otherwise it can be.

When a number can be so represented, there are infinitely many 
solutions.  Take one large enough, and there will be no other squares 
between n(n+1)/2 and n(n+1)/2 + k, so restricting the square to the 
next one, as you are doing, doesn't change which numbers can be 

What is happening is that we can write n(n+1)/2 + k = m^2.  Multiply by 
8 and rearrange algebraically, and you get:

2*(2m)^2 - (2n+1)^2 = 8k-1.

This is a generalized Pell equation, a subject that is well understood: 
see for example


Franklin T. Adams-Watters

-----Original Message-----
From: c.zizka at email.cz

Dear seqfans,

let a(n) is the difference between n-th triangular number and next 
square (submitted to OEIS today).

a(n)= (ceiling(n*(n+1)/2))^2 - n*(n+1)/2

Interestingly a(n) takes values 
{0,1,3,4,6,8,9,10,13,15,16,19,21,22,...} and it
seems no a(n) is from {2,5,7,11,12,14,17,18,20,23,...} .
In OEIS we can found for a(n)=0   A001108, for a(n)=1  A006451, for 
A154138,  for a(n)=4  A154139 , for a(n)=6  A154140, for a(n)=8  
A154141, for
a(n)=9   A154142, for a(n)=10  A154143.

Why can not be :

 (ceiling(n*(n+1)/2))^2  =  2+ n*(n+1)/2


More information about the SeqFan mailing list