Cake cutting | 프로그래밍의 벗 PivotOJ
PivotOJ

Cake cutting

시간 제한: 1000ms메모리 제한: 1024MB출처: EIO 2019-20 openBOJ 29916

문제

Kolya's grandmother from the cartoon "The Mystery of the Third Planet" baked a "small" rectangular cake. Since Kolya has many friends to share it with, the cake is really rather large. Kolya wanted to help his grandmother and cut the cake into unit squares. But he did not know that she still wanted to cover the cake with whipped cream.

The grandmother, not noticing Kolya's cuts, covered the cake with cream and cut it again. She is, however, a very old, very wise, and very artistic woman and cuts cakes in her own unique way. Specifically, she makes slanted cuts that form a square pattern among themselves, with the following rules:

  • The area of the squares formed by her cuts is always an integer.
  • Her first cut (diagonally up and to the rigth) starts from the lower left corner of the cake.
  • The first cut crossing it (diagonally down and to the right) intersects with it at the distance equal to the side length of the square of her pattern.

Into how many pieces did Kolya and his grandmother cut the cake?

입력

The only line of input contains five integers. First are MM (1M1091 \le M \le 10^9), the length of the cake (from left to right), and NN (1N1091 \le N \le 10^9), the width of the cake (from top to bottom). Thus, Kolya cuts the cake into M×NM \times N pieces.

Next is SS (1S1091 \le S \le 10^9), the area of the squares of grandmother's cuts. Note that this only applies to the pieces that are complete squares. As her cuts are slanted relative to the edges of the cake, some pieces are smaller than SS.

The last two numbers, PP and QQ (1P1031 \le P \le 10^3, 1Q1031 \le Q \le 10^3), describe the angle of her cuts. These mean that grandmother's first cut is made in the direction of the point that is PP units to the right and QQ units up from the corner. In other words, the angle between Kolya's and grandmother's cuts is atan(QP)\mathrm{atan}(\frac{Q}{P}).

In the late 22-nd century, when the story takes place, a new quantum law for cake cutting has been found: SP2+Q2\frac{S}{P^2+Q^2} is always a square of some rational number.

출력

The only line for output should contain a single integer: the total number of pieces into which the cake is cut by Kolya's and his grandmother's cuts.

예제

예제 1

입력
5 4 5 2 1
출력
36

예제 2

입력
7 8 8 1 1
출력
84

예제 3

입력
8 12 52 2 3
출력
122

예제 4

입력
3 3 5 11 2
출력
21
코드를 제출하려면 로그인하세요.