Question: C + + Given any positive integer n , define f ( n ) : = { n 2 i s e v e n

C++
Given any positive integer n, define
f(n):={n2iseven3n+1,nisodd.
The Collatz conjecture states that the sequence
ai:={n,i=0f(ai-1),i>0
eventually reaches 1. Write a function int collatzLength (int n) that
determines the first i for which ai=1 for a given n. For example, when n=
17, the sequence ai begins
17,52,26,13,40,20,10,5,16,8,4,2,1,dots
and a12=1. Thus, collatzLength (17) should return 12.
 C++ Given any positive integer n, define f(n):={n2iseven3n+1,nisodd. The Collatz conjecture

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!