This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
// 数论分块模板题,是很多题的基础,需要背诵
// j(n,k)=k%1+k%2+k%3+…+k%n
int n, k, l, r;
int ans;
signed main() {
cin >> n >> k;
ans = n * k; // 看题解的推导公式
for (l = 1; l <= n; l = r + 1) { // 枚举左端点,每次跳着走,下次的位置就是本次r的位置+1
if (k / l == 0) break; // 1、当k/l=0的时候,显然这段以及后面(有单调性)已经没有贡献了,可以 break。
r = min(k / (k / l), n); // 2、注意右端点和n取个min,因为>n没有贡献了。
ans -= (k / l) * (l + r) * (r - l + 1) / 2; // 等差数列求和:左到右边界内,是公差为1的等差数列,首项+末项 乘以 项数 除以2
}
cout << ans << endl;