The sons inherited and planted beans in a rectangle of dimensions beans.

Here is one way to arrive at this answer:

Let represent our elusive number of beans. We will go clue by clue imposing new conditions until we have met all of them.

We have three primary clues: There are (1) left when counting by , (2) left when counting by , and (3) left when counting by . There are some secondary clues, such as , which we will remember for later. For now, let's go to the first primary clue: if you count them by 's you end up with a remainder of . Then we can say for some , . The next clue is that leaves a remainder of when divided by , so then using the Chinese Remainder Theorem we will set up our second congruence using the results of the first:

Since , we expect one incongruent solution for . And by eying it, that would be

for some .

and , then

Now the last primary clue is that when the sons take one more than the other in sequence until impossible to continue the pattern, there are left, which gives us the equation

where represents the number of turns they go back and forth until they can no longer continue the pattern. This also implies that since if they took fewer turns than that and still had beans left, there would be enough beans to continue the pattern.

Previously we showed that , therefore

Here we can rewrite as since , and we then complete the square. So

Now we need to know what numbers when squared leave a remainder of when divided by . The quickest way to do this is with a chart. Since is not a perfect square, then we can eliminate every number whose square is less than , therefore let's start with . The calculations are expedited by use of a table of squares as well as a modulo calculator (there are some free apps for this).

We only have to go half-way to as the remaining will be a mirror reflection of the first half. In other words, if we extended our table further with , then we would expect . So it appears that we have two values less than , and by using the fact just mentioned, we can get the other two values greater than . So all give us . Thus

Now remember that . If we model the above congruences for as such:

for some , then we could apply the restriction to each case to get

for some .

We have a formula for (number of beans the boys inherited) in terms of () and we have all the values for , then we can calculate all possible values less than (the clue I said we would come back to!). The first four values of provide us all :

The last clue which will narrow the answer down to one is that there is only *one* way to form a rectangle out of the beans, which means that (1) is not prime (otherwise it couldn't be formed into a rectangle of more than one row), and (2) there is only one unique factorization for other than . Using an app for prime factorization, the following can be deduced very quickly:

So our only non-prime with one unique factorization is and we have our solution!