Processing math: 100%

Problem #209

Harry and Magic Squares

Harry and Hermione find an ancient square in the forest. Its vertices V1, V2, V3, V4 are each labeled with a number.

Hermione hates asymmetry, and she wants all numbers to be equal. Fortunately, Harry carries a magic wand with him. In one spell, he can choose any two adjacent vertices and increase their labels by one (each). He is allowed to use any amount of spells until the numbers become equal. Unfortunately, Harry is not so good at math, and he does not know if it is possible to make them equal.

Harry tells you that the initial values of the four numbers can be randomly distributed between 1 and 1000. Find the probability that he can use these spells to make all four labels of the vertices equal. Note that there is no restriction on the range of the final values of the magic numbers. If this probability can be expressed as p/q, where p and q are coprime numbers, enter the value of p.

Examples:

Case 1:
8 6
8 6
Here, Harry can apply the spell twice to make the four numbers equal to 8. Both spells act on the top-right and bottom-right vertices.

Case 2:
1 3
4 5
Here, any amount of spells will fail to achieve the end-goal of making all four labels equal.

Contributed by Parth Kohli

Solved by 38 users

Log in to submit answers.

Is something wrong?

Maintaining a collection of high quality questions is our top priority. If, however, you do find an error, report the problem and we'll make sure it is reviewed soon.