Problems > Interesting Series

Problem Statement

Collatz's conjecture claims that if we run the following algorithm on each integer:

If it is odd, we will multiply by 3 and add 1.
If it is even, we will divide it by 2.
Repeating this process over and over will always end up in the number 1.
For example: Starting with 1 will yield the following steps:
1→4→2→1
Starting with 3 will give us:

3→10→5→16→8→4→2→1

 

Your mission is to prove this conjecture :)

 

But assuming you are unable to prove it, your mission is to write a program that gets a single number, which is the start of the series (An integer, larger than 0). And calculate the sum of digits of all the numbers in the series.
In the first example the sum will be 1+4+2+1=8, and in the second example the sum is 3+1+0+5+1+6+8+4+2+1=31

 

Good luck!

Sample input #1

1

Sample output #1

8

Sample input #2

3

Sample output #2

31

Sample input #3

15

Sample output #3

100
You must be logged in to submit