Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

โปรแกรมคำนวณ Centered Icosahedral Number ใน C++

Centered Icosahedral Number (จำนวน Icosahedral กึ่งกลาง) แทนจำนวนจุดในการจัดเรียงรูป Icosahedron (ทรงยี่สิบหน้า) แบบมีจุดกึ่งกลาง

สูตรคำนวณ

พจน์ที่ n (เริ่มจาก n=1):

CI(n) = (2n + 1) × (5n² + 5n + 3) / 3

ลำดับตัวอย่าง (n = 1 ถึง 10)

1, 13, 55, 147, 309, 561, 923, 1415, 2057, 2869

การตรวจสอบสูตร

n2n+15n²+5n+3ผลคูณ/3
131313
253355
3763147
49103309
511153561

ตัวอย่าง

n = 20

Output: 28741

คำนวณ: (41) × (5×400 + 100 + 3) / 3 = 41 × 2103 / 3 = 41 × 701 = 28741

n = 12

Output: 6525

ตัวอย่างโค้ด

#include <iostream>
using namespace std;

long long centeredIcosahedral(int n) {
    // ใช้ long long ป้องกัน overflow
    // คำนวณแบ่งขั้นตอนเพื่อความแม่นยำ
    long long a = 2LL * n + 1;
    long long b = 5LL * n * n + 5LL * n + 3;
    return a * b / 3;
}

int main() {
    int n = 20;
    cout << "Centered Icosahedral Number (n=" << n << "): " 
         << centeredIcosahedral(n) << endl;
    
    n = 12;
    cout << "Centered Icosahedral Number (n=" << n << "): " 
         << centeredIcosahedral(n) << endl;
    
    // พิมพ์ series 10 ตัวแรก
    cout << "First 10 terms: ";
    for (int i = 1; i <= 10; i++) {
        cout << centeredIcosahedral(i);
        if (i < 10) cout << ", ";
    }
    cout << endl;
    
    return 0;
}

ผลลัพธ์

Centered Icosahedral Number (n=20): 28741
Centered Icosahedral Number (n=12): 6525
First 10 terms: 1, 13, 55, 147, 309, 561, 923, 1415, 2057, 2869

พื้นฐานทางเรขาคณิต

Icosahedron (ทรงยี่สิบหน้า) เป็น Polyhedron ที่มี:

  • 20 หน้า (Faces) – เป็นสามเหลี่ยมด้านเท่าทุกหน้า
  • 30 ขอบ (Edges)
  • 12 จุดยอด (Vertices)

Centered Icosahedral Number นับจุดในโครงสร้าง Icosahedron แบบ Layer-by-layer มีจุดกลาง 1 จุด

ความสัมพันธ์กับ Centered Polygonal Numbers อื่นๆ

สูตรทั่วไปสำหรับ Centered Polyhedral numbers (3D) ซับซ้อนกว่า 2D แต่ Icosahedral เป็นกรณีพิเศษที่มีสูตรปิด (Closed form) เป็นพหุนามดีกรี 3

ความซับซ้อน

  • เวลา: O(1) ต่อการคำนวณ
  • พื้นที่: O(1)

การใช้งาน

  • เรขาคณิตคอมพิวเตอร์ (Computer Graphics)
  • ทฤษฎีจำนวน (Number Theory)
  • การจำลองโครงสร้างผลึก (Crystallography)