**Description:**

A rectangle with sides equal to even integers `a`

and `b`

is drawn on the Cartesian plane. Its center (the intersection point of its diagonals) coincides with the point `(0, 0)`

, but the sides of the rectangle are not parallel to the axes; instead, they are forming `45`

degree angles with the axes.

How many points with integer coordinates are located inside the given rectangle (including on its sides)?

**Example**

For `a = 6`

and `b = 4`

, the output should be

`rectangleRotation(a, b) = 23`

.

The following picture illustrates the example, and the `23`

points are marked green.

**Input/Output**

**[time limit] 3000ms (cs)**

**[input] integer a**A positive even integer.*Constraints:*

`2 ≤ a ≤ 50`

.**[input] integer b**A positive even integer.*Constraints:*

`2 ≤ b ≤ 50`

.**[output] integer**The number of inner points with integer coordinates.

** Tests:**

**Explain:**

therefore 4 blue edges make 45 degrees angles so the 4 edges are corresponding 4 expressions:

- f
_{1}(x,y) = x + y + u = 0 - f
_{2}(x,y) = x + y – u = 0 - f
_{3}(x,y) = x – y + v = 0 - f
_{4}(x,y) = x – y – v = 0

therefore point O(0,0) is in the rectangle, So

- f
_{1}(0,0) = u > 0 - f
_{2}(0,0) = -u < 0 - f
_{3}(0,0) = v > 0 - f
_{4}(0,0) = -v < 0

If 1 point P(x,y) is in the rectangle then demands 4 conditions:

- f
_{1}(x,y) = x + y + u > 0 - f
_{2}(x,y) = x + y – u < 0 - f
_{3}(x,y) = x – y + v > 0 - f
_{4}(x,y) = x – y – v < 0

Mean: |x + y| < u and |x – y| < v

Now finding u, v:

Draws more 2 red lines perpendicular with 2 edges of the rectangle, we have right angled triangles, So u = a/sqrt(2), v = b/sqrt(2).

** Solution(C#):**

int rectangleRotation(int a, int b) { int r = 0; for (int x = -a - b; x &amp;amp;amp;amp;lt;= a + b; x++) { for (int y = -a - b; y &amp;amp;amp;amp;lt;= a + b; y++) { if (2 * (x - y) * (x - y) &amp;amp;amp;amp;lt;= a * a &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; 2 * (x + y) * (x + y) &amp;amp;amp;amp;lt;= b * b) r++; } } return r; }

this makes little sense. why would spanning the perimeter (-a-b to a+b) yield anything? There’s no shape information to that data. (ex. if a is 4 and b is 6, that range is the same as if a is 2 and b is 10)

LikeLike

Can we get any explanation at all?

LikeLike

I’m not good at English. Hope you can understand my explain above. Sees it in the post again.

LikeLike

Please update the new arcade solutions. Thanks you!

LikeLike