Input You have to read data from input file named, "input.txt". Each input has two integers, the first represents the pyramid height n, and second represents the secret room height m. Input is terminated by a sequence having n-0, m-0 which should not be processed. %3D Isns 2000000000, 0 Sm S n-2 Output You have to write output to the output file named, "output.txt". For each sequence, you are to output one line, containing the number of stones needed Input.txt Output.txt 6. 0. 56 55 52 36 171699 6. 1. 6. 2. 6. 4. 100 1

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Question-2:
A pyramids are discovered, each has a triangular base with equal sides. An n meters high
pyramid is constructed by forming n layers of triangles using Im cubical stones. Then layers are
stacked on top of each other. The first layer is the triangle with n meters base, on top, n-1 meters
base, until the top level which has only 1 stone. You are asked to calculate the number of stones
needed to build a pyramid with the height n.
WAIT! We just discovered that some pyramids have a secret room inside. This room is also of
the same shape and structure as the pyramid with m layers of stones removed. In order for the
room to be secret, m <n-2.
Figure 1. (0) 6 layers of stones, and (b) 6 meters high pyramid.
Example
The total number of stones needed to build a 6 meters high pyramid is
-(1+2+3+4+5+6)+( 1+2+3+4+5)+ (1+2+3+4)+ (1+2+3)+ (1+2)+1
-21 + 15+10 + 6+3+1-56.
If this pyramid has a 2 meters high secret room, then the total number of stones needed is 56-4
-52.
Input
You have to read data from input file named, "input.txt". Each input has two integers, the first
represents the pyramid height n, and second represents the secret room height m. Input is
terminated by a sequence having n 0, m 0 which should not be processed.
Isns 2000000000, 0 Sms n-2
Output
You have to write output to the output file named, "output.txt". For each sequence, you are to
output one line, containing the number of stones needed
Input.txt
Output.txt
6.
0.
6.
1.
6 2
6 4
100 1
56
55
52
36
171699
0.0
Transcribed Image Text:Question-2: A pyramids are discovered, each has a triangular base with equal sides. An n meters high pyramid is constructed by forming n layers of triangles using Im cubical stones. Then layers are stacked on top of each other. The first layer is the triangle with n meters base, on top, n-1 meters base, until the top level which has only 1 stone. You are asked to calculate the number of stones needed to build a pyramid with the height n. WAIT! We just discovered that some pyramids have a secret room inside. This room is also of the same shape and structure as the pyramid with m layers of stones removed. In order for the room to be secret, m <n-2. Figure 1. (0) 6 layers of stones, and (b) 6 meters high pyramid. Example The total number of stones needed to build a 6 meters high pyramid is -(1+2+3+4+5+6)+( 1+2+3+4+5)+ (1+2+3+4)+ (1+2+3)+ (1+2)+1 -21 + 15+10 + 6+3+1-56. If this pyramid has a 2 meters high secret room, then the total number of stones needed is 56-4 -52. Input You have to read data from input file named, "input.txt". Each input has two integers, the first represents the pyramid height n, and second represents the secret room height m. Input is terminated by a sequence having n 0, m 0 which should not be processed. Isns 2000000000, 0 Sms n-2 Output You have to write output to the output file named, "output.txt". For each sequence, you are to output one line, containing the number of stones needed Input.txt Output.txt 6. 0. 6. 1. 6 2 6 4 100 1 56 55 52 36 171699 0.0
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY