You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
824 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\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
2 years ago
if (k / l == 0) break; // 1、当k/l=0的时候比如3/4=0,3/5=0,3/6=0...,以后就都是0不用再往后算了无贡献
r = min(k / (k / l), n); // 2、注意右端点和n取个min>n没有贡献
ans -= (k / l) * (l + r) * (r - l + 1) / 2;
// 等差数列求和:首项:l,末项:r.项数:(r-l+1),根据公式推导k/l = 块内值
2 years ago
}
cout << ans << endl;
}