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. 1
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. 1
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
Related questions
Question
Please by using C++ compailar gdb
![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 1m' 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. (a) 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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7eea11db-073b-489e-84e1-4bd343ade79e%2F7f46e17f-ece4-41c0-9945-52b5440858ce%2Fl9bdct_processed.jpeg&w=3840&q=75)
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 1m' 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. (a) 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.
1<n< 2000000000, 0 <m< 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.
56
6.
1
55
6.
2
52
4
36
100 1
171699](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7eea11db-073b-489e-84e1-4bd343ade79e%2F7f46e17f-ece4-41c0-9945-52b5440858ce%2Fwkdth9a_processed.jpeg&w=3840&q=75)
Transcribed Image Text: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.
1<n< 2000000000, 0 <m< 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.
56
6.
1
55
6.
2
52
4
36
100 1
171699
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
![Operations Research : Applications and Algorithms](https://www.bartleby.com/isbn_cover_images/9780534380588/9780534380588_smallCoverImage.gif)
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
![Operations Research : Applications and Algorithms](https://www.bartleby.com/isbn_cover_images/9780534380588/9780534380588_smallCoverImage.gif)
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT