#include <iostream>
using namespace std;
float tong(int a) {
float tong1 = 0;
for (int i = 1; i <= a; i++)
tong1 += i;
return tong1;
}
float luythua(int a, int b) {
float lt = 1;
for (int i = 1; i <= b; i++)
lt *= a;
return lt;
}
float gt(int a) {
float gt1 = 1;
for (int i = 1; i <= a; i++)
gt1 *= i;
return gt1;
}
int main() {
freopen("tonghop.inp", "r", stdin);
freopen("tonghop.out", "w", stdout);
int x, n;
cin >> x >> n;
float s1 = 0;
float s2 = 0;
float s3 = 0;
float s4 = 0;
float s5 = 0;
for (int i = 1; i <= n; i++)
s1 += 1 / tong(i);
printf("%.2f\n", s1);
for (int i = 1; i <= n; i++)
s2 += luythua(i, i);
printf("%.1f\n", s2);
for (int i = 1; i <= n; i++)
s3 += luythua(x, i) / tong(i);
printf("%.1f\n", s3);
for (int i = 1; i <= n; i++)
s4 += luythua(x, i) / gt(i);
printf("%.1f\n", s4);
for (int i = 0; i <= n; i++)
s5 += luythua(x, 2 * i + 1) / gt(2 * i + 1);
printf("%.1f", s5);
}
#include <iostream>
using namespace std;
float tong(int a) {
float tong1 = 0;
for (int i = 1; i <= a; i++)
tong1 += i;
return tong1;
}
float luythua(int a, int b) {
float lt = 1;
for (int i = 1; i <= b; i++)
lt *= a;
return lt;
}
float gt(int a) {
float gt1 = 1;
for (int i = 1; i <= a; i++)
gt1 *= i;
return gt1;
}
int main() {
freopen("tonghop.inp", "r", stdin);
freopen("tonghop.out", "w", stdout);
int x, n;
cin >> x >> n;
float s1 = 0;
float s2 = 0;
float s3 = 0;
float s4 = 0;
float s5 = 0;
for (int i = 1; i <= n; i++)
s1 += 1 / tong(i);
for (int i = 1; i <= n; i++)
s2 += luythua(i, i);
for (int i = 1; i <= n; i++)
s3 += luythua(x, i) / tong(i);
for (int i = 1; i <= n; i++)
s4 += luythua(x, i) / gt(i);
for (int i = 0; i <= n; i++)
s5 += luythua(x, 2 * i + 1) / gt(2 * i + 1);
printf("%.2f\n", s1);
printf("%.1f\n", s2);
printf("%.1f\n", s3);
printf("%.1f\n", s4);
printf("%.1f", s5);
return 0
}
Sao 2 cái code trên khi test với test case 8 9 thì nó ra kết quả khác nhau ạ? Nó có liên quan tới bộ nhớ hay gì ko ạ?