码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-06 17:32:25      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:div   main   can   str   链接   def   int   type   long   

题目链接: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 }

 

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

标签:div   main   can   str   链接   def   int   type   long   

原文地址:http://www.cnblogs.com/halfrot/p/7631785.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!