[BZOJ1968][AHOI2005]COMMON约数研究 数学

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1968

直接计算每个因子的贡献就可以了。

$Ans=\sum_{i=1}^n[\frac{n}{i}]$

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 typedef long long ll;
 6 int main(){
 7     int N;
 8     scanf("%d",&N);
 9     ll ans=0;
10     for(int i=1;i<=N;i++) ans+=N/i;
11     printf("%lld\n",ans);
12     return 0;
13 }

 

posted @ 2017-10-06 17:01  halfrot  阅读(139)  评论(0编辑  收藏  举报