Sphere Online Judge

SPOJ Problem Set (classical)

515. Collatz

Problem code: CLTZ

Let N be a positive integer, Consider the following recurrence: f(1) = N and f(K) = (0.5 + 2.5 * (f(K-1) mod 2)) * f(K-1) + (f(K-1) mod 2) if K>1. For a given N you have to compute the smallest L for which f(L)=1 (such an L always exists for N's in the input).

Input

Each line contains a positive integer N in decimal notation. You can be sure that N and all intermediate results are not bigger than 10^1888. Input terminated by EOF.

Output

For each number N in the input print one line with the value of L in decimal notation.

Example

Input:
1
2
321
1111111111111
111111111111111111111111111111111111111111111111111111111111
Output:
1
2
25
261
1296

Added by:Noszály Csaba
Date:2005-04-25
Time limit:8s
Source limit:18000B
Languages:All except: C++ 4.3.2 C99 strict CLOJ ERL F# GO JS PERL 6 PYTH 3.1.2 SCALA TCL TECS
Resource:Folklore

hide comments
2010-08-27 16:31:32 Come On! Lets Code
how do we round off f(k-1) to find mod........f(k-1) is floating sometimes...
2010-07-04 00:30:10 kaushik.mv
yeah...Bruteforce is enough to solve this problem...:)
2010-06-25 17:01:23 Arpit Sood
resolved

Last edit: 2010-06-25 17:22:43
2010-06-22 05:30:32 sudipto das
It's so easy, still very few solved it......
Really surprising!!!!!!!!!!!

Last edit: 2010-06-22 05:31:18
2009-11-23 16:15:14 Muhammad Ridowan
Its from unproven Collatz conjecture. So probably there is no O(1) type solution.
2009-11-08 12:09:09 刘启鹏
i guess that brute force algorithm is enough for the problem.
SPOJ System © 2010 Sphere Research Labs. All Rights Reserved.