前置技能
(下取整函数)
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;
}
题目