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

约数和

时间:2018-07-12 10:30:10      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:amp   int   air   def   cto   cond   ==   new   ble   

简单来讲,就是要求$\sum_{i=1}^n(\sum_{d|i}d)$

$$\sum_{i=1}^n(\sum_{d|i}d)=\sum_{i=1}^n(\sum_{j=1}^n{[j|i]*j})=\sum_{j=1}^n(\sum_{i=1}^n{[j|i]*j})=\sum_{j=1}^n(j*{\lfloor}{\frac{n}{j}}{\rfloor})$$

$[j|i]$表示如果j是i的因子则为1,否则为0

(sigma性质?https://wenku.baidu.com/view/1006651014791711cc79171f.html

所以就跟https://www.cnblogs.com/hehe54321/p/7307069.html一样了。。。

题面就有很多了。。。


https://www.luogu.org/problemnew/show/P2424

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<vector>
 5 using namespace std;
 6 #define fi first
 7 #define se second
 8 #define mp make_pair
 9 #define pb push_back
10 typedef long long ll;
11 typedef unsigned long long ull;
12 typedef pair<int,int> pii;
13 ll x,y,ans;
14 int main()
15 {
16     ll i,j;
17     scanf("%lld%lld",&x,&y);
18     for(i=1;i<=y;i=j+1)
19     {
20         j=min(y,y/(y/i));
21         ans+=(y/i)*(i+j)*(j-i+1)/2;
22     }
23     x--;
24     for(i=1;i<=x;i=j+1)
25     {
26         j=min(x,x/(x/i));
27         ans-=(x/i)*(i+j)*(j-i+1)/2;
28     }
29     printf("%lld",ans);
30     return 0;
31 }

http://210.33.19.103/problem/3415

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<vector>
 5 using namespace std;
 6 #define fi first
 7 #define se second
 8 #define mp make_pair
 9 #define pb push_back
10 typedef long long ll;
11 typedef unsigned long long ull;
12 typedef pair<int,int> pii;
13 ll y,ans;
14 int main()
15 {
16     ll i,j;
17     scanf("%lld",&y);
18     if(y==0)
19     {
20         puts("0");
21         return 0;
22     }
23     for(i=1;i<=y;i=j+1)
24     {
25         j=min(y,y/(y/i));
26         ans+=(y/i)*(i+j)*(j-i+1)/2;
27     }
28     ans-=y;ans-=(y+1)*y/2;ans++;
29     printf("%lld",ans);
30     return 0;
31 }

 

约数和

标签:amp   int   air   def   cto   cond   ==   new   ble   

原文地址:https://www.cnblogs.com/hehe54321/p/9297605.html

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