每日一题洛谷P2669 [NOIP2015 普及组] 金币c++
#include<iostream>
using namespace std;
int main() {
int k;
cin >> k;
int sum = 0;
int n = 1;
while (k > 0) {
sum += n * n;
k -= n;
n++;
}
sum += k * (n - 1);
cout << sum << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
int k;
cin >> k;
int sum = 0;
int n = 1;
while (k > 0) {
sum += n * n;
k -= n;
n++;
}
sum += k * (n - 1);
cout << sum << endl;
return 0;
}