#P6159. Reflection on a Unit Circle
Reflection on a Unit Circle
Reflection on a Unit Circle
Rumia has a unit circle whose circumference is divided into n equal parts. The division points are denoted by \(A_0, A_1, A_2, \ldots, A_{n-1}\). She fires a beam of light from \(A_0\) toward \(A_p\). The beam then reflects off the circle k times (obeying the law of reflection) and finally reaches a point \(A_t\) on the circle. Your task is to determine the index \(t\) of the target point.
It can be shown that the reflection process makes the beam effectively “jump” a fixed number of points along the circle each time. In fact, after k reflections the final target point is given by
[ t \equiv (2k+1),p \pmod{n}. ]
For example, if \(k = 0\) the beam directly goes from \(A_0\) to \(A_p\), so \(t = p\). For \(k \ge 1\) the successive reflections add an extra rotation by \(2p\) (in terms of the index) per reflection.
Given \(n, p, k\), compute \(t\) using the above formula.
inputFormat
The input consists of a single line containing three integers \(n\), \(p\), and \(k\) separated by spaces:
n p k
where
- \(n\) is the number of equal segments the circle is divided into,
- \(p\) defines the index of the point \(A_p\) toward which the beam is initially fired, and
- \(k\) is the number of reflections.
outputFormat
Output a single integer \(t\) which is the index of the point \(A_t\) where the light beam eventually arrives. In other words, output the value of
[ t \equiv (2k+1),p \pmod{n}. ]
sample
6 1 1
3