GESP C++ Level 1 exam questions from September 2025, basic statement exercises, difficulty ★☆☆☆☆.
-
GESP Level 1 Practice Question List
-
GESP Level 1 Exam Question List
-
GESP Level 2 Practice Question List
-
GESP Level 2 Exam Question List
-
GESP Level 3 Practice Question List
-
GESP Level 3 Exam Question List
-
GESP Level 4 Practice Question List
-
GESP Level 4 Exam Question List
-
GESP Level 1-5 Syllabus Analysis
-
Essential Skills for GESP/CSP Programming
luogu-B4410 [GESP202509 Level 1] Pyramid
Problem Requirements
Problem Description
The pyramid is built with layers of stones. From the bottom to the top, each layer requires stones. How many stones are needed in total to build the pyramid?
Input Format
One line, a positive integer , representing the number of layers of the pyramid.
Output Format
One line, a positive integer, representing the total number of stones required to build the pyramid.
Input/Output Example #1
Input #1
2
Output #1
5
Input/Output Example #2
Input #2
5
Output #2
55
Notes/Tips
For all test cases, it is guaranteed that .
Problem Analysis
The number of stones required for each layer of the pyramid from bottom to top is .The total number of stones is to be calculated.
Since , either direct accumulation or using a formula can be applied, with a time complexity of or , and space .
Conventional Approach: Accumulation Method
Using a loop to accumulate the stones layer by layer, the code is straightforward and suitable for beginners. The example code implements this method.
Elementary Math Expert Approach: Formula Method
Directly applying the square sum formula , calculates the answer in one step, which is the most efficient. (Everyone can try it themselves)
Example Code
#include <iostream>
int main() {
int n; // Number of layers of the pyramid
std::cin >> n; // Read the number of layers n from user input
int count = 0; // Initialize total stone count to 0
// Loop from layer n to layer 1, calculating the number of stones for each layer i*i and accumulating to count
for (int i = n; i > 0; i--) {
count += i * i; // Number of stones for each layer is i×i
}
std::cout << count << std::endl; // Output the total number of stones required
return 0;
}
For detailed GESP syllabus, exam question explanations, knowledge expansion, and practice lists, see:
[Pinned] [GESP] C++ Certification Learning Resource Compilation
“luogu-” series questions can be evaluated online at Luogu Question Bank.
“bcqm-” series questions can be evaluated online at Programming Enlightenment Question Bank.