#P6159. [Cnoi2020] 光图

[Cnoi2020] 光图

Description

Rumia has a unit circle, divided into nn equal parts, and the division points are denoted as A0A_0, A1A_1, A2A_2, \cdots , An1A_{n-1}.

Now she emits a beam of light from A0A_0 toward ApA_p. After k1k - 1 reflections, it arrives at AtA_t.

Rumia wants to know the value of tt. Since Cirno does not want to help her, Rumia turns to you for help.

Input Format

One line with three integers, n,p,kn, p, k.

Output Format

One line with one integer tt.

12 5 2
10
1000 342 3472844
648

Hint

Explanation of Sample 1

Physical knowledge used later

  • Reflection law on a continuous curve: The incident ray and the reflected ray make equal angles with the tangent line of the curve at the point of incidence.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (80%80\%): n,k106n, k \le 10^6.
  • Subtask 2 (20%20\%): n,k109n, k \le 10^9.

For 100%100\% of the testdata: 0<p<n1090 < p < n \le 10^9, 0<k1090 < k \le 10^9.

Postscript

  • The light diagram obtained by Cirno is the legendary twelve-pointed star diagram.

Translated by ChatGPT 5