#K94407. Marble Pyramid Levels
Marble Pyramid Levels
Marble Pyramid Levels
You are given an integer (n) representing the number of marbles. Your task is to determine the maximum number of complete levels of a pyramid that can be built using these marbles, where the (i)-th level requires exactly (i) marbles. In other words, you need to find the largest integer (k) such that
[ 1 + 2 + \cdots + k \le n, \quad \text{or} \quad \frac{k(k+1)}{2} \le n. ]
If there are not enough marbles to build even the first level, output 0.
Example:
For (n = 15), the maximum number of complete levels is 5 because (1 + 2 + 3 + 4 + 5 = 15).
inputFormat
The input consists of a single integer (n) denoting the number of marbles. Read the input from stdin.
outputFormat
Output a single integer representing the maximum number of complete levels that can be constructed, printed to stdout.## sample
15
5