#P12048. Rotating Polygon Return Cycle
Rotating Polygon Return Cycle
Rotating Polygon Return Cycle
A moving regular polygon (an m-gon) with side length a is rotating clockwise around a fixed regular polygon (an n-gon) with side length b. Initially, the m-gon is positioned so that one of its sides is flush with one end of a side of the n-gon.
The rotation process is as follows: in each move the m-gon is rotated about the common contact point (one end of the shared edge) until a different vertex (and hence a different side of m-gon) touches the n-gon. Through elementary geometry one can prove that the m-gon rotates through an angle of \(\frac{2\pi}{m}\) in every move. Meanwhile, the contact point on the n-gon shifts to the next vertex, which means that after each rotation the moving polygon “steps” along the perimeter of the n-gon.
The moving polygon is considered to have returned to its original location once its position (its placement relative to the fixed polygon) is the same as initially. Note that the m-gon does not have to have each of its sides in exactly the original place (its sides are indistinguishable); it only matters that the overall position be the same.
This happens if and only if after \(k\) rotations both of the following conditions are met:
- The total rotation of the m-gon is an integer multiple of \(2\pi\), i.e. \(k\cdot\frac{2\pi}{m}\equiv0 \pmod{2\pi}\). This implies that \(m\) divides \(k\).
- The contact point on the n-gon has cycled back to its starting position. Since the contact point moves to the next vertex with each rotation, after \(k\) moves it has advanced by \(k\) vertices. In order for it to return to the starting vertex, \(n\) must divide \(k\).
Thus, the minimum number \(k\) of rotations required is given by the least common multiple (\(\mathrm{lcm}\)) of \(m\) and \(n\):
[ k=\mathrm{lcm}(m, n). ]
inputFormat
The input consists of a single line containing four space-separated positive integers: a m b n
, where:
a
is the side length of the moving regular m-gon.m
(\(m \ge 3\)) is the number of sides of the moving polygon.b
is the side length of the fixed regular n-gon.n
(\(n \ge 3\)) is the number of sides of the fixed polygon.
Note: Although a
and b
are given, the final answer depends only on \(m\) and \(n\).
outputFormat
Output a single integer, the minimum number of rotations needed for the m-gon to return to its original position. In other words, output \(\mathrm{lcm}(m,n)\).
sample
1 3 1 3
3