มีเหรียญ n เหรียญ จัดเป็นพีระมิดสูงสุด ชั้นแรก 1 เหรียญ ชั้นที่ 2 -> 2 เหรียญ ชั้นที่ 3 -> 3 เหรียญ ...

ตัวอย่าง: 6 เหรียญ สร้างพีระมิดสูง 3 ชั้น (1+2+3=6) ไม่สามารถสร้างชั้น 4 ได้ (ต้อง 10 เหรียญ) สูตรหาความสูง:
H = (-1 + sqrt(1 + 8N)) / 2
Input: n = 10 Output: Height of pyramid: 4
คำอธิบาย
ใช้สูตร H = (-1 + sqrt(1 + 8N)) / 2
ตัวอย่าง
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int n = 10;
int height = (-1 + sqrt(1 + 8 * n)) / 2;
cout << "Height of pyramid: " << height;
}