시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB124292052.632%

문제

상근이와 친구들이 술자리에서 하는 게임은 소수 사이클 게임이다. 각 사람은 1번부터 N번으로 나타낸다.

게임을 시작하기에 앞서 동그란 의자 N-1개와 네모난 의자 1개를 준비한다. 의자는 원을 이루어서 배치한다. 먼저, 1번이 네모난 의자에 앉고, 다음 2번부터는 반시계방향으로 차례대로 의자에 앉는다. 모든 사람은 원의 중심을 바라보고 있다.

게임은 총 K개 라운드로 이루어져 있다. i번째 라운드 시작되면 네모에 앉은 사람이 자리에서 일어나서 "내가 네모야!"라고 외친다. 그 다음, 오른쪽에 있는 사람과 자리를 총 Pi번 바꾸게 된다. Pi는 i번째 작은 소수이다.

아래는 N=5, K=3인 예이다.

  1. 라운드: 
  2. 라운드: 
  3. 라운드: 

N, K, A가 주어졌을 때, 게임이 끝난 후에 A의 이웃을 구하는 프로그램을 작성하시오. 

입력

첫째 줄에 N, K, A가 주어진다. (3 ≤ N ≤ 5,000,000, 1 ≤ K ≤ 500,000, 1 ≤ A ≤ N)

출력

게임이 끝난 후에 A의 오른쪽에 있는 사람과 왼쪽에 있는 사람을 출력한다.

예제 입력 1

5 3 1

예제 출력 1

3 5

예제 입력 2

5 3 2

예제 출력 2

5 4

예제 입력 3

5 4 5

예제 출력 3

3 2
W3sicHJvYmxlbV9pZCI6IjI4ODIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMxOGNcdWMyMTggXHVjMGFjXHVjNzc0XHVkMDc0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWMwYzFcdWFkZmNcdWM3NzRcdWM2NDAgXHVjZTVjXHVhZDZjXHViNGU0XHVjNzc0IFx1YzIyMFx1Yzc5MFx1YjlhY1x1YzVkMFx1YzExYyBcdWQ1NThcdWIyOTQgXHVhYzhjXHVjNzg0XHVjNzQwIFx1YzE4Y1x1YzIxOCBcdWMwYWNcdWM3NzRcdWQwNzQgXHVhYzhjXHVjNzg0XHVjN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Highschool Competitions in Informatics > 2010 > Croatian Olympiad in Informatics 2010 2번