Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a java program for the problem statement Problem Statement The goal is to sort numbers by their Collatz length. It is conjectured that any

write a java program for the problem statement image text in transcribed
image text in transcribed
Problem Statement The goal is to sort numbers by their Collatz length. It is conjectured that any number can be reduced to 1 by following these steps: 1) If the number is even divide it in 2 2) If the number is odd, multiply by 3 and add 1 See here for more details on the Collatz sequence: https://en.wikipedia.org/wiki/Collatz_co njecture Let's call "Collatz length" the number of steps needed to reduce a number to 1. The Collatz length of 1 is zero, since no steps are needed. Whereas the Collatz length of 4 is two, since two steps are needed: 4 -> 2-> 1. Every number will have a Collatz length. The goal is to sort a set of numbers in a given range by their Collatz sequence, and then output the xth number in the sorted list. If two numbers have the same Collatz length, then the smaller number should come first. Note: These numbers can get very long and exceed the limit of a Java int (2,147,483,647). It's a good idea then to use longs rather than ints. Input Format An integer a which indicates the start of the range An integer b which indicates the end of the range, inclusive Note: These numbers can get very long and exceed the limit of a Java int (2,147,483,647). It's a good idea then to use longs rather than ints. Input Format An integer a which indicates the start of the range An integer b which indicates the end of the range, inclusive A target integer x Output Format An integer which is the xth number in the list that results when the numbers from a to b inclusive are sorted according to Collatz length Constraints a,b>0 a,b

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago