You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
453 B
27 lines
453 B
2 years ago
|
#include <bits/stdc++.h>
|
||
|
|
||
|
using namespace std;
|
||
|
/**
|
||
|
8
|
||
|
4 2
|
||
|
|
||
|
1
|
||
|
2 2
|
||
|
3 3 3
|
||
|
4 4 4 4
|
||
|
*/
|
||
|
int n, sum;
|
||
|
int main() {
|
||
|
cin >> n;
|
||
|
for (int i = 1;; i++) {
|
||
|
n -= i;
|
||
|
if (n <= 0) {
|
||
|
// cout << i << " " << i + n << endl;
|
||
|
sum += i * (i + n); // 最后一行
|
||
|
for (int j = 1; j < i; j++) sum += j * j;
|
||
|
cout << sum << endl;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|