시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 128 MB 139 34 24 43.636%

문제

x의 P승을(1 ≤ P ≤ 20,000) 최대한 빠르게 계산하고자 한다. 그런데 계산결과가 굉장히 크므로 여기서는 계산 도중 값을 저장하는 데 있어 두 개의 변수만을 사용한다.

두 변수 중 하나는 x로, 다른 하나는 1로 초기화되어 있다. 우리가 쓸 수 있는 연산은, 현재 저장되어 있는 값들을 서로 곱하거나 나누어서 그 결과값을 임의의 변수에 저장하는 것이다. 최종 결과가 저장되는 위치는 아무래도 좋다.

예를 들어 x9을 계산하고자 할 때, 다음과 같은 방법이 가능하다.

연산 회수 0 1 2 3 4
변수1 x x x x5 x9
변수2 1 x2 x4 x4 x4

P를 입력받아, xP를 구하기 위한 최소 연산 회수를 구하여라.

입력

첫째 줄에 P가 들어온다.

출력

최소 연산 회수를 출력한다.

예제 입력 1

31

예제 출력 1

6
W3sicHJvYmxlbV9pZCI6IjIwNzQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWFjNzBcdWI0ZWRcdWM4MWNcdWFjZjEgXHVhY2M0XHVjMGIwXHVkNTU4XHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD54XHVjNzU4IFBcdWMyYjlcdWM3NDQoMSAmbGU7IFAgJmxlOyAyMCwwMDApIFx1Y2Q1Y1x1YjMwMFx1ZDU1YyBcdWJlNjBcdWI5NzRcdWFjOGMgXHVhY2M0XHVjMGIwXHVkNTU4XHVhY2UwXHVjNzkwIFx1ZDU1Y1x1YjJlNC4gXHVhZGY4XHViN2YwXHViMzcwIFx1YWNjNFx1YzBiMFx1YWNiMFx1YWNmY1x1YWMwMCBcdWFkNDlcdWM3YTVcdWQ3ODggXHVkMDZjXHViYmMwXHViODVjIFx1YzVlY1x1YWUzMFx1YzExY1x1YjI5NCBcdWFjYzRcdWMwYjAgXHViM2M0XHVjOTExIFx1YWMxMlx1Yzc0NCBcdWM4MDBcdWM3YTVcdWQ1NThcdWIyO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AgICAgICAgICAgICAgICAgTXVsdGlwbHkgc2Vjb25kIGJ5IHNlY29uZDogICB4ICAgeF44XHJcblxyXG4gICAgICAgICAgICAgICAgICBNdWx0aXBseSBzZWNvbmQgYnkgc2Vjb25kOiAgIHggICB4XjE2XHJcblxyXG4gICAgICAgICAgICAgICAgICBNdWx0aXBseSBzZWNvbmQgYnkgc2Vjb25kOiAgIHggICB4XjMyXHJcblxyXG4gICAgICAgICAgICAgICAgICAgICBEaXZpZGUgc2Vjb25kIGJ5IGZpcnN0OiAgIHggICB4XjMxXHJcbjxcL3ByZT5cclxuXHJcbjxwPlRodXMsIHheMzEgY2FuIGNvbXB1dGVkIGluIHNpeCBvcGVyYXRpb25zLiBHaXZlbiB0aGUgcG93ZXIgdG8gYmUgY29tcHV0ZWQgYW5kIHRoZSB0aGUgbnVtYmVyIG9mIHdvcmsgdmFyaWFibGVzLCBmaW5kIHRoZSBtaW5pbXVtIG51bWJlciBvZiBvcGVyYXRpb25zIHRvIGNhbGN1bGF0ZSB0aGUgcG93ZXIuPFwvcD5cclxuIiwiaW5wdXQiOiI8cD5BIHNpbmdsZSBsaW5lIHdpdGggb25lIGludGVnZXI6IFAuPFwvcD5cclxuIiwib3V0cHV0IjoiPHA+QSBzaW5nbGUgbGluZSB3aXRoIGEgc2luZ2xlIGludGVnZXIgdGhhdCBpcyB0aGUgbWluaW11bSBudW1iZXIgb2Ygb3BlcmF0aW9ucyBpdCByZXF1aXJlcyB0byBjb21wdXRlIHRoZSBwb3dlci48XC9wPlxyXG4iLCJoaW50IjoiIiwib3JpZ2luYWwiOiIxIiwiaHRtbF90aXRsZSI6IjAiLCJwcm9ibGVtX2xhbmdfdGNvZGUiOiJFbmdsaXNoIn1d

출처

  • 데이터를 추가한 사람: doju
  • 문제의 오타를 찾은 사람: kcm1700