Learn programming with Lao Ma while “leveling up and battling monsters”!
This aims to provide comprehensive learning materials for children to prepare for the level examination together.
Add the assistant on WeChat and reply with 【GESP Level 1 2025.09_Pyramid】 to obtain the source code for this problem.
GESP Level 1 2025.09_Pyramid
[Submit]
https://www.luogu.com.cn/problem/B4410
[Problem Description]
The pyramid is built with layers of stones. From the bottom to the top, each layer requires , , , , stones respectively. How many stones are needed in total to build the pyramid?
[Input Description]
A single line containing a positive integer , representing the number of layers in the pyramid.
[Output Description]
A single line containing a positive integer, representing the number of stones required to build the pyramid.
[Sample Input 1]
2
[Sample Output 1]
5
[Sample Input 2]
5
[Sample Output 2]
55
[Hint]
For all test cases, it is guaranteed that .
Reference Answer:
/*
* [GESP202509 Level 1] Pyramid
* https://www.luogu.com.cn/problem/B4410
*/
#include <iostream>
using namespace std;
int main()
{
int n, ans = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
ans += i * i;
}
cout << ans << endl;
return 0;
}
Youth Programming Competition Exchange
The “Youth Programming Competition Exchange Group” has been established (suitable for youth aged 6 to 18). Add the assistant on WeChat to invite everyone into the study group. After joining, everyone can participate in regularly organized 21-day problem-solving challenges, level examination assessments, guidance for Ministry of Education whitelist competitions, and youth programming team competitions.
