ในปัญหานี้ เราได้รับ N งานคือหาผลรวม Series: √3 + √12 + √27 + √48 + ... จน N พจน์
ตัวอย่าง
Input: N = 3 Output: 10.3922
√3 + √12 + √27 = 1.732 + 3.464 + 5.196 = 10.392
การ導出สูตร
พจน์ที่ k: √(3k²) = k√3
Sum = √3 × Σ(k) = √3 × N(N+1)/2
ตัวอย่างโค้ด
#include <iostream>
#include <cmath>
using namespace std;
double calcSumNTerms(int n) {
return sqrt(3) * n * (n + 1) / 2.0;
}
int main() {
cout << calcSumNTerms(25); // 562.917
return 0;
}
ผลลัพธ์
562.917