Even-Odd Series Sum

The following iterative sequence is defined for the set of positive integers:

{ n = n 2 if n is even. n = 3 n + 1 if n is odd. \begin{cases} n = \dfrac n2 & \text{if }n \text{ is even.} \\ n = 3n + 1 & \text{if }n \text{ is odd.} \end{cases}

When the initial value of n n is 13 the following sequence is formed and converges at 1:

13 40 20 10 5 16 8 4 2 1 \begin{array} {c} 13 & 40 & 20 & 10 & 5 & 16 & 8 & 4 & 2 & 1\end{array}

What is the sum of all terms when n = 100 n=100 ?


The answer is 808.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

The computation can be easily done with a Microsoft Excel spreadsheet as follows. Enter at cell A1: "100", cell A2: "=IF(MOD(A1,2)=0,A1/2,3*A1+1)" and copy through to A26, that is until n = 1 n=1 . Then enter at cell A27: "=SUM(A1:A26)" to sum up all the n n 's.

Same here !

Nikola Alfredi - 1 year, 4 months ago
Steven Chase
Feb 8, 2020
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
n = 100

sum = n
flag = 0

while flag == 0:

    if n%2 == 0:
        n = n/2
    else:
        n = 3*n + 1

    sum = sum + n

    if n == 1:
        flag = 1

print sum
# 808

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...