硬拆方法
#include
using namespace std;
int main() {
int n, t = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
t += i * i;
}
cout << t;
return 0;
}
结局并不完美,找了一会发现超出数字范围,改了int格式为longlong如下:
#include
using namespace std;
int main() {
long long n, t = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
t += i * i;
}
cout << t;
return 0;
}