0
$\begingroup$

I was going through this website where I found 3n + 1 problem.

I was not able to understand what the output should be.

I understood if the input is 1 and 10 then the numbers between 1 to 10 need to be in consideration, and the output will be 20. But I am wondering how it can be 20.

Where as 10 - 10 5 16 8 4 2 1. (Total 6 excluding 16). Then how can be it 20?

Please could you please help me.

Please make me understand the problem, What it really wants me to solve?

Please tell me if I had put some wrong tag

1 Answers 1

6

If the input is $i=1$ and $j=10$ then you need to consider the full cycle for each starting value $i=1\le n \le 10=j$, consider all of their "cycle lengths" and return the largest cycle length.

For $n=10$ the cycle length is 7, since you need to include 16.

Given $i=1,j=10$ as input, the cycle length for $n=1$ is $1$, for $n=2$ is 2, for $n=3$ is $8$, and for $n=4,5,6,7,8,9,10$ is respectively $3,6,9,17,4,20,7$. The largest value in this range is 20, which should be your answer.

Similarly, if $i=100,j=200$, then the longest cycle length is $125$ which you find starting with $n=171$ then considering the full cycle $C=\{171,514,257,772,\ldots,4,2,1\},\vert C\vert=125$.

  • 0
    @Zander: Thanks a lot, for making me understand...2012-06-28