Pyramids
Time limit1sMemory limit128 MB
For each positive base size n until a terminating 0, print the total number of blocks in a pyramid whose layers count down from n to 1.
- Level
Easy1 of 10
- Topics
- Math, Implementation, Brute force, Array
- Solved
- No attempts yet
Problem
A pyramid of blocks is built by first laying a base layer of blocks, then placing blocks on the layer above it. Each successive layer uses one fewer block than the layer below, and this continues until the top layer holds a single block.

Given the size of the base layer, determine the total number of blocks needed to complete the pyramid. For example, a pyramid whose base has size needs blocks in total.
Input
The input is a sequence of integers, one per line. The end of the input is marked by the integer , which is not the base of any pyramid. Every integer except the final is positive.
Output
For each positive integer, print the total number of blocks needed to build the pyramid whose base has that size, one result per line.