Logo
(追記) (追記ここまで)

29916번 - Cake cutting 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB1000.000%

문제

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 $M$ (1ドル \le M \le 10^9$), the length of the cake (from left to right), and $N$ (1ドル \le N \le 10^9$), the width of the cake (from top to bottom). Thus, Kolya cuts the cake into $M \times N$ pieces.

Next is $S$ (1ドル \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 $S$.

The last two numbers, $P$ and $Q$ (1ドル \le P \le 10^3,ドル 1ドル \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 $P$ units to the right and $Q$ units up from the corner. In other words, the angle between Kolya's and grandmother's cuts is $\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: $\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

예제 출력 1

36

예제 입력 2

7 8 8 1 1

예제 출력 2

84

예제 입력 3

8 12 52 2 3

예제 출력 3

122

예제 입력 4

3 3 5 11 2

예제 출력 4

21

힌트

출처

Olympiad > Estonian Informatics Olympiad > 2019-20 > Open Competition 6번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /