#P6159. [Cnoi2020] 光图

[Cnoi2020] 光图

Background

Greatness is hidden in simplicity.

Cirno casually divided a circle with total internal reflection into 1212 equal parts, and the division points are denoted as A0A_0, A1A_1, A2A_2, \cdots , A11A_{11}.

Then, she casually emitted a beam of light from one point toward another point. By repeating, reflecting, and iterating, she obtained a beautiful light diagram.

All of this happened casually.

She casually noticed this scene, and casually wrote down this casual conclusion, and at some moment casually recalled it.

Every day in Gensokyo is so carefree. What a nice day.

Problem 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