余数之和
分析
见《进阶指南》第141
页。
代码
#include <iostream>
using namespace std;
typedef long long LL;
int main () {
LL n, k;
cin >> n >> k;
LL res = n * k;
for (LL l = 1, r; l <= n; l = r + 1) {
if (k / l == 0) {
r = n;
} else {
r = min(k / (k / l), n);
}
res -= (r - l + 1) * (k / l) * (l + r) / 2;
}
cout << res << endl;
return 0;
}