求代码,100分的代码,谢谢!
#include <bits/stdc++.h>
using namespace std;
int main() { int k, i = 0, a = 0, b = 0; cin >> k; while (b <= k) { i++; a += i * i; b = (i + 1) * i / 2; } a -= (b - k) * i; cout << a; return 0; }
共 1 条回复
#include <bits/stdc++.h>
using namespace std;
int main() { int k, i = 0, a = 0, b = 0; cin >> k; while (b <= k) { i++; a += i * i; b = (i + 1) * i / 2; } a -= (b - k) * i; cout << a; return 0; }