## 简要做法

$$ans = \sum_{i = 1}^n k \bmod i$$

$$ans = \sum_{i = 1}^n(k- i \times {\lfloor\frac{k}{i}\rfloor})$$

$$ans = n \times k - \sum_{i = 1}^n (i \times \lfloor\frac{k}{i}\rfloor)$$

$i$ $1$ $2$ $3$ $4$ $5$ $6$ $7$ $8$ $9$ $10$
$\lfloor\frac{k}{i}\rfloor$ $5$ $2$ $1$ $1$ $1$ $0$ $0$ $0$ $0$ $0$

• 若$t \ne 0$

则 $r = min(\lfloor\frac{k}{t}\rfloor,n)$

• 若$t = 0$

则 $r = n$

• 若 $i \le \sqrt k$ 最多只有 $\sqrt k$ 种取值
• 若 $i > \sqrt k$ 则 $\lfloor\frac{k}{i}\rfloor < \sqrt k$ 取值也不超过 $\sqrt k$ 种

## 参考代码

#include <stdio.h>
#include <algorithm>

long long n, k, ans;

int main()
{
scanf("%lld%lld", &n, &k);
ans = n * k;
for (long long l = 1, r; l <= n; l = r + 1)
{
long long t = k / l;
if (t == 0)
r = n;
else
r = std::min(k / t, n);
ans -= t * (r - l + 1) * (l + r) / 2;
}
printf("%lld", ans);
return 0;
}