A set of numbers is called Almost-squarish if it satisfies the following two properties:

The set contains only positive integers.
The product of any two distinct numbers in the set is one less than a perfect square.

A trivial example of a Almost-squarish set is {4, 12} because $4 \cdot 12 = 7^2-1$.

Can you find an example of an Almost-squarish set with 4 elements?

BONUS: Do there exist Almost-squarish sets with more than 4 elements?


Today I learned from Gerry Myerson’s answer that this is a problem that has been studied for a long time:

Almost-squarish sets with four elements exist but not with five.


4 Answers 4


The first few almost-square numbers are: $3,8,15$

And we notice that $3\times 8=24$ is the next almost-square number.

As such, we have the almost-squarish set $\{1,3,8\}$ with 3 distinct elements.

If we continue to examine almost-square numbers, we soon find this:

$1\times 120=11^2-1\\3\times 120=360=19^2-1\\8\times 120=960=31^2-1$

Which expands the 3-element almost-squarish set, giving us the 4-element almost-squarish set



The existence of a "Diophantine quintuple" was an open question for many years.

It was settled in the negative in 2016 by He, Togbe, and Ziegler.

See https://en.wikipedia.org/wiki/Diophantine_quintuple for details.

  • $\begingroup$ Welcome to Puzzling Stack Exchange! Great answer! $\endgroup$ Commented Jun 2, 2023 at 23:00

Some hand analysis first.

Suppose we have numbers A<B<C<D, there are obviously no two equal numbers. We first pick arbitrary number N. Then let A=N-1, B=N+1, so A*B = N² - 1. Now we can use C*A = (2N-1)²-1 = 4N²-4N = 4N(N-1). This sets C=4N Then C*B = 4N*(N+1) = (2N+1)² - 1. Finally, we require D. If we take D=(4N²-1)*C we get DC = (4N²-1)*(16N²) = 64N⁴-16N² = (8N²-1)² - 1, DB = (4N²-1)*4N*(N+1) = 16N⁴+16N³-4N²-4N = (4N²+2N-1)² - 1 and DA = (4N²-1)*4N*(N-1) = 16N⁴-16N³-4N²+4N = (4N²-2N-1)² - 1.

This is sufficient to prove there are infinitely many 4 element sets.

These are NOT all of the 4 element options.

For example, there are also 1,8,15,528 or 2, 12, 24, 2380.

I believe you can start with any number (at all), then pick any number that generates almost square with the first one (there are infinitely many), then pick any third number that generates almost square with the first two (I guess still infinitely many options "but way fewer than before" - you know what I mean...), then pick the unique fourth number. As the fourth number is unique, there is obviously no fifth. But I don't know how to prove this, this is mainly how my test code seems to spit out results (ignoring limited search range. 1e6 in example; I tried this with up to 1e8 but it looks the same)

Code (matlab, most likely works in octave too but I haven't tried it there). findSQS does the actual looping and calling itself, while printing final possibilities. Initial thingy outside the function is to ensure we can start findSQS with arbitrary number, such as 1 or 2.

sqm = (1:1e6).^2 - 1;
for initCand = 1:1000
    initList = sqm / initCand; 
    initList(initList ~= round(initList)) = [];
    initList(initList <= initCand) = [];
    [elems] = findSQS(initCand, initList, initList);

function [nextElems, nextList] = findSQS(elems, sqm, remList)

if (isempty(remList)) % no more numbers to add, print what we have.
    nextElems = elems
    nextList = [];

for i = 1 : length(remList) % pick any number still on the list, starting with first one.
    NE = remList(i);
    nextElems = [elems, NE]; % add element
    nextList = sqm / NE; % all almost squares with the current one, after we
    nextList(nextList ~= round(nextList)) = []; % delete non-integers
    nextList(nextList < NE) = []; % and remove smaller numbers (remove duplicate sets).
    nextList = intersect(remList, nextList); % Find intersection of that list with numbers not ruled out by previous elements.
    [nextElems, nextList] = findSQS(nextElems, sqm, nextList); % And call itself again.

  • $\begingroup$ The claim that the fourth one must be unique is your hypothesis? How did you arrive into that hypothesis? $\endgroup$
    – justhalf
    Commented Jun 1, 2023 at 12:51
  • $\begingroup$ @justhalf "But I don't know how to prove this, this is mainly how my test code seems to spit out results" For example, I saw quite many 1, 3, C, D that appear, but for each C there was a single D, never another option. So, infinite C, single D. I might be also able to calculate D in terms of previous values (perhaps that formula in the first part, just replacing N with As and Bs...). But I have no idea how to show it is the only option. $\endgroup$ Commented Jun 1, 2023 at 13:05
  • $\begingroup$ Got it. For me, intuitively I don't feel there should be a hard limit at 4 if the question hadn't asked specifically for that (which caused me to not continue that thought), so am interested in how other people may intuitively come up with that hypothesis. $\endgroup$
    – justhalf
    Commented Jun 1, 2023 at 13:08
  • $\begingroup$ There are triplets that allow more than one extension, for example 1,3,120 (8 or 1680). $\endgroup$
    – loopy walt
    Commented Jun 1, 2023 at 22:19
  • 1
    $\begingroup$ The above should be A<B... @smci The upper part is to prove there are infinitely many ABCD as you can pick any N and find a set ABCD. I suspect you can pick ANY number A, ANY suitable B, ANY suitable C and find unique D. The first set of solutions mentioned in Daniel's answer is for N=2 and is the smallest. As for coprime, nope. One solution is 2 4 12 420, which is obviously not coprime. And there is 3 5 16 1008 where ABC are coprime but A is not 1. $\endgroup$ Commented Jun 2, 2023 at 7:04

While trying to make my own code to generate all the groups of 4 I found a pattern. I don't know if we could expand it to eventually find a 5th element but i found that if you include 1, most of the solutions use the following format :


Here are some examples

1,3,8,120 (N=2)
1,35,48,6888 (N=6)
1,48,63,12320 (N=7)
1,63,80,20448 (N=8)
1,80,99,32040 (N=9)
And the list goes on for any N>1

Obviously there are some outliers but there is still a pattern for most of them


  • $\begingroup$ Welcome to Puzzling Stack Exchange! Great answer! $\endgroup$ Commented Jun 2, 2023 at 18:04
  • $\begingroup$ Neat. How can we generalize so it also covers the A!=1 cases e.g. {3, 5, 16, 1008}? $\endgroup$
    – smci
    Commented Jun 12, 2023 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.