#include <bits/stdc++.h>
using namespace std;
// Hàm tính tổng 1 + 2 + ... + k
double tong(int k) {
return k * (k + 1) / 2.0;
}
// S1
double S1(int n) {
double s = 0;
for (int i = 1; i <= n; i++)
s += 1.0 / tong(i);
return s;
}
// S2
double S2(int n) {
double s = 0;
for (int i = 1; i <= n; i++)
s += pow(i, n);
return s;
}
// S3
double S3(int x, int n) {
double s = 0;
for (int i = 1; i <= n; i++)
s += pow(x, i) / tong(i);
return s;
}
// S4
double S4(int x, int n) {
double s = 0, gt = 1;
for (int i = 1; i <= n; i++) {
gt *= i;
s += pow(x, i) / gt;
}
return s;
}
// S5
double S5(int x, int n) {
double s = 0, gt = 1;
for (int i = 1; i <= 2 * n + 1; i++) {
gt *= i;
if (i % 2 == 1) {
int k = (i - 1) / 2;
if (k < n)
s += pow(x, i) / gt;
}
}
return s;
}
int main() {
int x, n;
cin >> x >> n;
cout << fixed << setprecision(2) << S1(n) << endl;
cout << fixed << setprecision(1) << S2(n) << endl;
cout << fixed << setprecision(1) << S3(x, n) << endl;
cout << fixed << setprecision(1) << S4(x, n) << endl;
cout << fixed << setprecision(1) << S5(x, n) << endl;
return 0;
}
dùng c++
