시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 152 75 65 57.018%

문제

상덕이와 희원이는 동전 게임을 하면서 시간을 보낸다. 동전 게임은 동전 N개를 가지고 하는 게임이고, 규칙은 다음과 같다.

  1. 상덕이가 먼저 게임을 하고, 그 다음엔 희원이, 그 다음에 상덕이, 희원이 순서대로 게임을 한다. 순서대로 첫 번째 턴, 두 번째 턴, 세 번째 턴, ...
  2. 상덕이는 첫 번째 턴에서 가져갈 수 있는 동전의 개수는 1보다 크거나 같고, N보다 작거나 같다.
  3. 그 다음 턴부터는 동전을 이전 턴에서 그 사람이 가져간 동전 개수의 최대 2배만큼 가져갈 수 있다. (동전을 적어도 1개는 가져가야 한다)
  4. 이렇게 플레이를 하다가 마지막 동전을 가져가는 사람이 이긴다.

상덕이와 희원이가 항상 최적의 방법으로 게임을 한다. 이 말은 어떤 상황에서 플레이어 A가 B를 항상 이길 수 있다면, A가 항상 이긴다는 것이다.)

이때, 상덕이가 이기기 위해서는 첫 번째 턴에서 동전을 몇 개 가져가야 하는지를 구하는 프로그램을 작성하면 된다. 이러한 동전의 개수가 여러 개 나올 수 있는데, 그 때는 가장 적은 개수를 출력하면 된다.

입력

첫째 줄에 동전의 개수 N이 주어진다. (2<=N<=1015)

출력

첫째 줄에 상덕이가 이기기 위해서 가져가야 하는 동전 개수의 최솟값을 출력한다.

예제 입력 1

4

예제 출력 1

1

힌트

동전의 개수가 4개일 때, 상덕이가 첫 번째 턴에서 가져갈 수 있는 동전의 경우의 수는 1, 2, 3, 4개이다. 만약 4개를 가져가게 된다면 상덕이는 항상 이기게 된다. 하지만, 이것은 최솟값이 아니다. 상덕이가 첫 번째 턴에서 동전을 1개 가져갔다고 생각해보자. 그럼 이제 동전은 3개가 남고, 희원이는 동전을 많아야 2개만 가져갈 수 있기 때문에 절대 이길 수 없게 된다. (문제의 3번 조건 때문에 희원이는 동전을 1*2개까지 가져갈 수 있다) 희원이가 동전을 1개를 가져가던, 2개를 가져가던 상덕이는 다음 턴에서 남은 동전을 모두 가져갈 수 있기 때문에 상덕이가 첫 번째 턴에서 동전을 1개 가져가면 항상 이기게 된다. 따라서 정답은 1이다.

W3sicHJvYmxlbV9pZCI6IjI4NjIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMyMThcdWQ1NTkgXHVhYzhjXHVjNzg0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWMwYzFcdWIzNTVcdWM3NzRcdWM2NDAgXHVkNzZjXHVjNmQwXHVjNzc0XHViMjk0IFx1YjNkOVx1YzgwNCBcdWFjOGNcdWM3ODRcdWM3NDQgXHVkNTU4XHViYTc0XHVjMTFjIFx1YzJkY1x1YWMwNFx1Yzc0NCBcdWJjZjRcdWIwYjhcdWIyZTQuIFx1YjNkOVx1YzgwNCBcdWFjOGNcdWM3ODRcdWM3NDAgXHViM2Q5XHVjODA0IE5cdWFjMWNcdWI5N2MgXHVhYzAwXHVjOWMwXHVhY2UwIFx1ZDU1OFx1YjI5NCBcdWFjOGNcdWM3ODRcdWM3NzRcdWFjZTAsIFx1YWRkY1x1Y2U1OVx1Yzc0MCBcdWIyZTRcdWM3NGNcdWFjZmMgXHVhYzE5XHViMmU0LjxcL3A+XHJcblxyXG48b2w+XHJcblx0PGxpPlx1YzBjMVx1YjM1NVx1Yzc3NFx1YWMwMCBcdWJhM2NcdWM4MDAgXHVhYzhjXHVjNzg0XHVjNzQ0IFx1ZDU1OFx1YWNlMCwgXHVhZGY4IFx1YjJlNFx1Yzc0Y1x1YzVkNCBcdWQ3NmNcdWM2ZDBcdWM3NzQsIFx1YWRmOCBcdWIyZTRcdWM3NGNcdWM1ZDAgXHVjMGMxXHViMzU1XHVjNzc0LCBcdWQ3NmNcdWM2ZDBcdWM3NzQgXHVjMjFjXHVjMTFjXHViMzAwXHViODVjIFx1YWM4Y1x1Yzc4NFx1Yzc0NCBcdWQ1NWNcdWIyZTQuIFx1YzIxY1x1YzExY1x1YjMwMFx1Yjg1YyBcdW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