1. The 3n + 1 problem


Submit solution

Points: 10
Time limit: 60.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Prolog

考拉茲猜想(Collatz conjecture),對於每一個正整數 n,如果它是奇數,則對它乘3再加1,如果它是偶數,則對它除以2,如此循環,最終都能夠得到1。

如n = 6,根據上述公式,

6/2 = 3
3*3+1 = 10
10/2 = 5
3*5+1 = 16
16/2 = 8
8/2 = 4
4/2 = 2
2/2 = 1

得出序列 6, 3, 10, 5, 16, 8, 4, 2, 1,共有 9 個數字

Input

一個整數 n, 1 <= n <= 1000

Output

n 經過上述演算法所產生的序列數字數量。


Sample Input1

1

Sample Output1

1

Sample Input2

3

Sample Output2

8

Sample Input3

6

Sample Output3

9


注意事項


  1. 繳交期限:2021-04-23 Fri. 23:59
  2. 10筆測資必須全部通過才算分

Comments

There are no comments at the moment.