# Mosaic in the bathroom and Diophantine equations

It was in the evening, before going to bed. I brushed my teeth and looked tiredly at the mosaic in the bathroom. For some reason, I was interested in such a simple fact: if a rectangle of 2 × 3 cells is surrounded by cells on both sides, the area of ​​the stroke will be the same as the area of ​​the rectangle:

There are exactly as many blue squares as yellow ones. And then I suffered.

I wondered if there are still such configurations. That is, to make the rectanglecircle with a contour on both sides, and the area of ​​the contour coincides with the area of ​​the rectangle. Of course and  must be integer:

It seems that such cases should no longer be. The area of ​​the blue partand yellow . It can be seen that if or  unit, then there will be no matches, and if you increase them more then the blue will clearly grow faster. So this configuration is one.

Bored, said the brain. We must weaken the task. So to speak:

But now the task is too weak. In fact, you need to select two rectangles with integer sides, so that their areas differ exactly by half. And the restriction on rectangles is only that one can be thrust into the other. There are too many of them, too boring. Let's do this:

Fix the border width. How many are there? Hm. It looks more interesting. Yellow Square is, and we want her to equal just . That is, we (me and my brain, which dragged me into this) need to solve the equation:



Or, the same thing:



By this time, I had finished with my teeth and started pouring powder into the dishwasher. Yeah, the brain said, not a bad challenge. It is necessary to solve, of course, in integers, that is, this is a Diophantine equation . We did not go through the Diophantine equations at the university, but I remembered something about them from popular articles. Namely:

• If we have a homogeneous equation, then we are lucky.
• It is easy to turn a homogeneous equation on integers into an equation on rational ones, reducing the number of variables by one.
• If, using the method of peering, to find some root of the quadratic equation on rational numbers, then it is easy to find all the others.
• Any straight line with rational coefficients passing through a known root will go through another root. Twisting this line, you can get all the rational roots.

In this way, for example, the general formula for all the Pythagorean triples is easily found . By the way, as with the Pythagorean triples, in our problem any number of multiple solutions. For example, a rectanglecan be expanded with a border in two small squares and so on. Of course, we are only interested in multiple solutions.

Will I be able to do all this in my mind, I thought, picking up a moisturizer. An algebra without a piece of paper and a computer is a rather insidious thing: mixed up a plus with a minus or forgot some member, and further calculations are in vain. Programmers know what to do to reduce the likelihood of an error - they need to be surrounded by unit tests. Fortunately, we already know one solution:. We will check it at every step.



So far, so good. So, we have a homogeneous equation - all terms are included in the second degree. Divide the equation by (happening  we are not interested, so you can share):



Making a replacement:  and we get an equation with two rational variables:



In our unit test , the test passes. Now we need to draw a straight line. In principle, it can be drawn just through the pointbut it’s hard to keep in the brain. But by the method of peering, we can easily find another point that satisfies the equation:. This corresponds to zero areaand again, as a solution, it’s not very interesting, but for a direct one just right. It’s quite simple to notice that all the lines (except one) passing throughare described by an explicit equation (yes, for some reason the brain gave out the Greek letter, although the Latin ones did not end yet). One missing line isShe is also not very interesting to us. Of course, any rational pointwhere  consistent rational . For example, for a point value . We substitute the equation of the line into our equation and get:



Or



Or



Or



It becomes difficult to bring members in the head; the brain desperately asks for a piece of paper. But I lull the baby in my arms, there’s no time for a piece of paper. Run the unit test ():



Fuf, so far so good. Now we have a quadratic equation forwhich should actually give a rational root for any rational . How can this be, there is discriminant and all that? Okay, let's try:



Oh, oh, well, a full square came out. Endorphin went to the brain. He, a freak addict, seems to have sought this. Here it is the magic of mathematics: a rational number should have come out and it came out. Recall the formulas for the roots:



Or in our notation:





 Is our reference point It’s not interesting for us. Our solution is. Substituting it in we get the answer:



That is, you just need to sort out all the rational fractions as , и для них мы получим все рациональные решения уравнения  (ну кроме некоторых, которые нам не очень интересны).

Разумеется, перебирать проще целые числа, а не рациональные. Спаивая младенцу препарат симетикона, я подставляю  и получаю:





(Боже, мозг, зачем ты выбрал именно  и ? Они так легко путаются в голове! Букв мало что ли?) В нашем юнит-тесте, если , то подойдут  и легко убедиться, что тест проходит.

Как нам вернуться к целым числам? Вспоминаем, что мы заменили . Значит, надо принять за  любое число, кратное общему знаменателю из формул выше. В частности, подходит просто . В итоге имеем:



Видно, что если  и  не взаимно простые, то и решение будет кратно их общему делителю, поэтому нам интересны только взаимно простые  и . Кратное решение также получится, если  окажется чётным. В самом деле пусть . Тогда



Если поделить всё на два, то получим



Это решение симметрично первому, что вполне логично: ведь задача симметрична относительно  и . Таким образом, нам интересны взаимно простые  и , причём  нечётно.

Удобно, что выражение для  получилось таким простым. Значит, у нас есть простой способ найти все некратные решения для заданной наперёд ширины окантовки : это такие прямоугольники , где  любой нечётный делитель , взаимно простой с . Следующий прямоугольник будет для :

И голубая, и жёлтая часть содержат ровно по 30 клеточек!

Давайте посмотрим, какие ещё есть решения для маленьких  ( и  я кое-где переставил, чтобы шли по возрастанию):

xnmплощадь без окантовкиплощадь с окантовкой
1112 × 3 = 63 × 4 = 12
2123 × 10 = 305 × 12 = 60
3134 × 21 = 847 × 24 = 168
3315 × 12 = 608 × 15 = 120
4145 × 36 = 1809 × 40 = 360
5156 × 55 = 33011 × 60 = 660
5517 × 30 = 21012 × 35 = 420
6167 × 78 = 54613 × 84 = 1092
63214 × 15 = 21020 × 21 = 420

By counting these works in the head, the brain again achieved a dose of endorphin. How beautiful and wonderful divisors flow from one number to another! Take for example: the first is divided by 6, and the second is 11. We add a five to both numbers, and a miracle - now the first is divided by 11, and the second - by 6. And there are such tricks in each line! And here, and the son seemed to calm down. Eleven in the evening, you can go to bed.

Perhaps all this can be counted easier. Perhaps my reasoning was somewhere inaccurate. Perhaps these numbers and works have some special name. I do not know - did not look. I’m more interested in this: I’m the only nonsense to occupy my consciousness, or you toosufferare you enjoying Will they treat us?