题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1257
\( \sum\limits_{i=1}^{n}k\%i = \sum\limits_{i=1}^{n}k-\left \lfloor k/i \right \rfloor *i \)
然后数论分块做即可,注意 \( n>k \) 时右边界的取值。
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,k;
ll ans;
ll cal(int l,int r){return (ll)(l+r)*(r-l+)/;}
int main()
{
scanf("%d%d",&n,&k); ans=(ll)n*k;
for(int i=,j;i<=n/*&&i<=k*/;i=j+)
{
if(k/i)j=min(n,k/(k/i));//min
else j=n;
ans-=(ll)(k/i)*cal(i,j);
}
printf("%lld\n",ans);
return ;
}