标签:using 研究 namespace 分块 clu inline cli ace its
设 \(f(x) = \sum_{d | x}{1}\), 求 \(\sum_{i = 1}^{N}f(x)\) 即 \(\sum_{i=1}^{N} \sum_{d | x}{1}\)
考虑枚举约数 \(d\) , 发现 \(d\) 在 \(1-N\) 中出现 \(\lfloor \frac{N}{d} \rfloor\) 次
所以答案就为: \[\sum_{d = 1}^{N}\lfloor \frac{N}{d} \rfloor\]
除法分块优化, 复杂度 \(O(\sqrt{N})\)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<climits>
typedef long long LL;
using namespace std;
LL RD(){
LL out = 0,flag = 1;char c = getchar();
while(c < '0' || c >'9'){if(c == '-')flag = -1;c = getchar();}
while(c >= '0' && c <= '9'){out = out * 10 + c - '0';c = getchar();}
return flag * out;
}
LL num;
LL get_num(LL n){
LL ans = 0;
for(LL l = 1, r;l <= n;l = r + 1){
r = n / (n / l);
ans += (n / l) * (r - l + 1);
}
return ans;
}
int main(){
num = RD();
printf("%lld\n", get_num(num));
return 0;
}
标签:using 研究 namespace 分块 clu inline cli ace its
原文地址:https://www.cnblogs.com/Tony-Double-Sky/p/9507988.html