loj125 除数函数求和 2

https://loj.ac/problem/125

$原式=2\sum_{i=1}^n(i^2*{\lfloor}{\frac{n}{i}}{\rfloor})+3\sum_{i=1}^n(i*{\lfloor}{\frac{n}{i}}{\rfloor})+5\sum_{i=1}^n({\lfloor}{\frac{n}{i}}{\rfloor})$

 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 #define md 998244353
14 ll n,a1,a2,a3;
15 ll calc(ll x)    {return x*(x+1)%md*(2*x+1)%md*166374059%md;}
16 int main()
17 {
18     ll i,j,t;
19     scanf("%lld",&n);
20     for(i=1;i<=n;i=j+1)
21     {
22         t=n/i;
23         j=min(n,n/t);
24         a1=(a1+(calc(j)-calc(i-1)+md)%md*t%md)%md;
25         a2=(a2+(i+j)*(j-i+1)%md*499122177%md*t%md)%md;
26         a3=(a3+(j-i+1)*t)%md;
27     }
28     printf("%lld",(2*a1+3*a2+5*a3)%md);
29     return 0;
30 }

 

posted @ 2018-07-12 13:06  hehe_54321  阅读(366)  评论(0编辑  收藏  举报
AmazingCounters.com