Files
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

18 lines
824 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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
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 = 块内值
}
cout << ans << endl;
}