标签:pac stream 计算 数论 bre long cpp ret iostream
将原式变形,很容易得到以下式子:
对于\(\lfloor\frac{k}{i}\rfloor=x\),可得出\(\max i=\lfloor \frac{k}{x} \rfloor\)
计算每一块的\(l,r\),高斯求和即可
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,r;
long long ans;
int main()
{
scanf("%d%d",&n,&k);
ans=(long long)n*(long long)k;
for (int l=1;l<=n;l=r+1)
{
if (k/l==0)
break;
r=k/(k/l);
r=min(r,n);
ans-=(long long)(k/l)*(long long)(l+r)*(long long)(r-l+1)/2LL;
}
cout << ans << endl;
return 0;
}
标签:pac stream 计算 数论 bre long cpp ret iostream
原文地址:https://www.cnblogs.com/GK0328/p/13347191.html