The hailstone sequence is formed in the following way:

If n is even, divide it by 2 to get n'
if n is odd, multiply it by 3 and add l to get n'

It is conjectured that for any positive integer number n, the sequence will always end in the repeating cycle: 4, 2, 1, 4, 2, 1,.... Suffice to say, when n = = 1, we will say the sequence has ended.

Write a program to determine the largest value in the sequence for a given n.


The first line of input contains a single integer P, (1$ \le$P$ \le$100000), which is the number of data sets that follow. Each data set should be processed identically and independently.

Each data set consists of a single line of input consisting of two space separated decimal integers. The first integer is the data set number. The second integer is n, (l$ \le$n$ \le$100, 000), which is the starting value.


For each data set there is a single line of output consisting of the data set number, a single space, and the largest value in the sequence starting at and including n.

Sample Input

1 1
2 3
3 9999
4 100000

Sample Output

1 1
2 16
3 101248
4 100000

INDENT THE CODE And comment it.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <iostream>

using namespace std;

int main()
int nstart, n, max; //Declare variables
while(true) //Endless loop to keep running new starting values
max = 0; //Reset max value
cout << "Please enter in the starting value (0 to exit): "; //Next two lines, prompt and read integer for n, assume valid inputs > 0 always...

By purchasing this solution you'll be able to access the following files:

50% discount

$18.00 $9.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats