莫比乌斯反演准备

前置技能
d = 1 n [ n / d ] \sum_{d=1}^n{[n/d]} (下取整函数)
n<1e14;
对于[n/d] 的每个取值,对应d的范围一定是一个区间,枚举[n/d]的取值即可。

#include<cstdio>
#include<iostream>

using namespace std;
typedef long long LL;

int main(){
   LL n=0;
   scanf("%lld",&n);
   LL ans=0;
   for (LL i=1;i<=n;i++){
   	LL t=n/i,j=n/t;
   	ans+=(j-i+1)*t;//(j-i+1)为区间
	   i=j; 
   }	
   printf("%lld\n",ans);
	return 0;
} 

题目
i = 1 n i = 1 m d ( i j ) \sum_{i=1}^n\sum_{i=1}^md(ij)

猜你喜欢

转载自blog.csdn.net/qq_36172410/article/details/89105584
今日推荐