选定的k一定是n的因数。
代码:
#include<bits/stdc++.h>
using namespace std;#define read(x) scanf("%d",&x)
#define ll long longint n;ll cnt(int d) {
int x=n/d;return (2+((ll)x-1)*d)*x/2;
}int main() {
read(n);vector<ll> ans;for(int i=1;i<=sqrt(n);i++) {
if(n%i) continue;ans.push_back(cnt(i));if(i*i!=n) ans.push_back(cnt(n/i));}sort(ans.begin(),ans.end());for(int i=0;i<ans.size();i++) {
printf("%I64d ",ans[i]);}return 0;
}