Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C language and recursion There is a fractal consists of infinitely many horizontal segments, which are numbered by integers started from 1. The i-th

Use C language and recursion

There is a fractal consists of infinitely many horizontal segments, which are numbered by integers started from 1. The i-th segment is represented by the range [XL[i], XR[i]], where XL[i] and XR[i] are integers, and XL[i] XR[i]. Here is the algorithm to construct the fractal. The fractal starts with the first segment XL[1] = XR[1] = 1. Then, for every iteration, it follows these steps:

Supposed that segment 1 to K have been generated by the previous iteration.

First, add (K + 1)-th segment where XL[K + 1] = 1 and XR[K + 1] = K + 1.

Then, the next K segments are the translation of the first K segments. Formally, for all segment i where 1 i K, add (K +1+i)-th segment where XL[K +1+i] = XL[i] + K and XR[K + 1 + i] = XR[i] + K.

At first, there is only segment 1. After the first iteration, there will be 1 + 1 + 1 = 3 segments. After the second iteration, there will be 3 + 1 + 3 = 7 segments. After the third iteration, there will be 7+1+7 = 15 segments. By repeating the iteration infinitely many times, the whole fractal can be created.

Since it is impossible to create a program which output infinitely many segments, it is only asked to output XL[i] and XR[i] for all segments i where A i B.

The following illustration is the step by step of creating the segments from the second iteration to the third iteration.

image text in transcribed

Format Input

A single line consists of 2 integers, A and B.

Format Output

Output (B A + 1) lines. Each line consists of 2 integers, which describes the asked

segments.

Constraints

1 A B 10^9

1 (B A + 1) 3 10^4

Sample Input 1 (standard input)

1 16

Sample Output 1 (standard output)

1 1

1 2

3 3

1 4

5 5

5 6

7 7

1 8

9 9

9 10

11 11

9 12

13 13

13 14

15 15

1 16

Sample Input 2 (standard input)

999999994 1000000000

Sample Output 2 (standard output)

999999993 999999994

999999995 999999995

999999993 999999996

999999997 999999997

999999997 999999998

999999999 999999999

999999489 1000000000

Explanation

The first illustration represents the output in the first sample.

1. Initial Condition from the 2nd iteration. There are 7 segments. 1 2 3 4 5 6 7 2. Add the 8th segment, from X=1 to 8 1 2 3 4 5 6 7 8 3. Translate the 1st.. 7th segments to 9th..15th, and this is the result of the 3rd iteration. 1. Initial Condition from the 2nd iteration. There are 7 segments. 1 2 3 4 5 6 7 2. Add the 8th segment, from X=1 to 8 1 2 3 4 5 6 7 8 3. Translate the 1st.. 7th segments to 9th..15th, and this is the result of the 3rd iteration

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

More Books

Students also viewed these Databases questions

Question

2. How were various roles filled?

Answered: 1 week ago