시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 393 164 140 48.611%

문제

상덕이와 희원이는 동전 게임을 하면서 시간을 보낸다. 동전 게임은 동전 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+XHJcblx0PGxpPlx1YzBjMVx1YjM1NVx1Yzc3NFx1YWMwMCBcdWJhM2NcdWM4MDAgXHVhYzhjXHVjNzg0XHVjNzQ0IFx1ZDU1OFx1YWNlMCwgXHVhZGY4IFx1YjJlNFx1Yzc0Y1x1YzVkNCBcdWQ3NmNcdWM2ZDBcdWM3NzQsIFx1YWRmOCBcdWIyZTRcdWM3NGNcdWM1ZDAgXHVjMGMxXHViMzU1XHVjNzc0LCBcdWQ3NmNcdWM2ZDBcdWM3NzQgXHVjMjFjXHVjMTFjXHViMzAwXHViODVjIFx1YWM4Y1x1Yzc4NFx1Yzc0NCBcdWQ1NWNcdWIyZTQuIFx1YzIxY1x1YzExY1x1YjMwMFx1Yjg1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