Given a natural number n, generate a sequence of integers described in the Collatz conjecture: If n is even, divide it i
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Given a natural number n, generate a sequence of integers described in the Collatz conjecture: If n is even, divide it i
Given a natural number n, generate a sequence of integers described in the Collatz conjecture: If n is even, divide it in half. If it is odd, multiply it by 3 and add 1. Repeat this operation until reaching 1. For example, if n = 17, the sequence looks as follows: 17 52 26 13 40 20 10 5 16 8 421 The conjecture states that such a sequence will eventually reach 1 for any value of n. O Output format: Sequence of integers in a single line, separated by single spaces. For example: Input Result 18 18 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!