아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Laws

시간 제한2초메모리 제한256 MB

요약
x개의 동전에서 시작해 하루가 지나면 1개가 늘고, 2나 3으로 나누어떨어질 때마다 절반 또는 3분의 1로 줄일 수 있다. 정확히 1개를 남기는 최소 일수와 그 과정을 출력한다.
난이도

보통10점 중 7점

유형
BFS, 그래프, 수학
정답자
아직 제출이 없습니다

문제

There are two inhabitants in the Faraway Kingdom: Alyonushka the Peasant and Ivanushka the King. Alyonushka works on a farm, and Ivanushka makes laws.

Alyonushka has xx coins. Each day, Alyonushka gets one more coin from the treasury for her work. The amount of coins in the treasury can be considered infinite.

If the number of Alyonushka's coins divides evenly by two, Ivanushka can make another peasant law, and Alyonushka will be allowed to keep only half of her coins: the other half immediately goes to the treasury. If the number of Alyonushka's coins divides evenly by three, Ivanushka can make another farm law, and Alyonushka will be allowed to keep only one third of her coins: the other two thirds immediately go to the treasury. Ivanushka can make new laws at any moment, in any order, and do it any number of times.

Today Ivanushka got angry with Alyonushka. Now he wishes Alyonushka to have only one coin left. What is the minimum possible number of days required to achieve that?

입력

The first line of input contains an integer xx: the initial number of Alyonushka's coins (1≤x≤1091 \le x \le 10^{9}).

출력

On the first line, print tt: the minimum possible number of days required for Ivanushka to leave Alyonushka with only one coin. On the second line, print a sequence of integers: any possible sequence of events which takes tt days and transforms xx coins into 11. The sequence must start with xx and end with 11. Every two consecutive numbers uu and vv in the sequence must satisfy either v=u+1v = u + 1 (a day has passed), v=u/2v = u / 2 (a new peasant law has been made), or v=u/3v = u / 3 (a new farm law has been made).

예제3

  1. 예제 1

    입력
    11
    
    예상 출력
    1
    11 12 6 2 1
    
  2. 예제 2

    입력
    100
    
    예상 출력
    2
    100 50 25 26 27 9 3 1
    
  3. 예제 3

    입력
    1
    
    예상 출력
    0
    1