# 例题一

$\sum_{i=1}^n \lfloor\frac n i\rfloor\\$

for(LL l=1,r;l<=n;l=r+1)
{
r=n/(n/l);
ans+=(n/l)*(r-l+1);
}


# 例题二

$\sum_{i=1}^nk\bmod i\\$

$\sum_{i=1}^nk\bmod i\\ =\sum_{i=1}^nk-i\lfloor\frac k i\rfloor\\ =nk-\sum_{i=1}^ni\lfloor\frac k i\rfloor\\$

ans=n*k;
for(LL l=1,r;l<=n&&l<=k;l=r+1)
{
r=min(k/(k/l),n);
ans-=(k/l)*(r+l)*(r-l+1)/2;
}


# 例题三

$$\sum\limits_{i=L}^R f(i)$$

# 例题四

$\sum_{i=1}^n\sum_{j=1}^m (n\bmod i)(m\bmod j)\\$

$\sum_{i=1}^n\sum_{j=1}^m (n\bmod i)(m\bmod i)\\ =\sum_{i=1}^n(n\bmod i)\sum_{j=1}^m (m\bmod j)\\ =\sum_{i=1}^n(n-i\lfloor\frac n i\rfloor)\sum_{j=1}^m (m-j\lfloor\frac m j\rfloor)\\ =(n^2-\sum_{i=1}^n i\lfloor\frac n i\rfloor)(m^2-\sum_{j=1}^m m\lfloor\frac m j\rfloor)\\$

# 例题五

$\sum_{i=1}^n (n\bmod i)(m\bmod i)\\$

$\sum_{i=1}^n (n\bmod i)(m\bmod i)\\ =\sum_{i=1}^n (n-i\lfloor\frac n i\rfloor)(m-i\lfloor\frac m i\rfloor)\\ =\sum_{i=1}^n (nm-(n+m)i\lfloor\frac n i\rfloor+i^2\lfloor\frac n i\rfloor\lfloor\frac m i\rfloor)\\ =n^2m-(n+m)\sum_{i=1}^n i\lfloor\frac n i\rfloor+\sum_{i=1}^n i^2\lfloor\dfrac n i\rfloor\lfloor\frac m i\rfloor\\$

for(LL l=1,r=0;l<=n;l=r+1)
{
r=min(n/(n/l),m/(m/l));
ans=ans+(n/l)*(m/l)*(sum(r)-sum(l-1));
}



posted @ 2023-05-08 19:35  DengDuck  阅读(31)  评论(0编辑  收藏  举报