'commit'
This commit is contained in:
18
TangDou/AcWing_TiGao/T5/RongChi/199.cpp
Normal file
18
TangDou/AcWing_TiGao/T5/RongChi/199.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user