# bzoj4815 [Cqoi2017]小Q的表格

……

$f_{a,b}=f_{b,a}$，这个就是对称性。

$b×f_{a,a+b}=(a+b)×f_{a,b}$，这个有点意思。整道题明明就是这里最难好嘛

\begin{align}\sum_{d=1}^n f(d)\sum_{i=1}^n\sum_{j=1}^n[(i,j)=d]\frac{ij}{d^2}\\=\sum_{d=1}^n f(d)\sum_{i=1}^{\left\lfloor\frac n d\right\rfloor}\sum_{j=1}^{\left\lfloor\frac n d\right\rfloor}[(i,j)=1]ij\end{align}

\begin{align}\sum_{i=1}^n\sum_{j=1}^n[(i,j)=1]ij=\sum_{i=1}^n i^2\varphi(i)\end{align}

\begin{align}Ans=\sum_{d=1}^n f(d)\sum_{i=1}^{\left\lfloor\frac n d\right\rfloor}i^2\varphi(i)\end{align}

 1 #include<cstdio>
2 #include<cstring>
3 #include<cmath>
4 #include<algorithm>
5 using namespace std;
6 const int maxn=4000010,maxb=2010,p=1000000007;
7 void phi_table(int);
8 void modify(int,int);
9 int query(int);
10 int gcd(int,int);
11 bool notp[maxn]={false};
12 int prime[maxn]={0},phi[maxn];
13 int id[maxn],L[maxb],R[maxb],cntb=0;
14 int f[maxn],sum[maxn]={0},lazy[maxb]={0};
15 long long x;
16 int n,B,m,a,b,k,ans;
17 int main(){
18     scanf("%d%d",&m,&n);
19     B=(int)(sqrt(n)+0.5);
20     for(int i=1;i<=n;i++){
21         id[i]=(i-1)/B+1;
22         if(!L[id[i]])L[id[i]]=i;
23         R[id[i]]=i;
24         cntb=id[i];
25         f[i]=(long long)i*i%p;
26         sum[i]=(sum[i-1]+f[i])%p;
27     }
28     phi_table(n);
29     while(m--){
30         scanf("%d%d%lld%d",&a,&b,&x,&k);
31         int g=gcd(a,b);
32         x/=(long long)(a/g)*(b/g);
33         x%=p;
34         modify(g,(x-f[g]+p)%p);
35         f[g]=x;
36         ans=0;
37         for(int i=1,last;i<=k;i=last+1){
38             last=k/(k/i);
39             ans=(ans+(long long)(query(last)-query(i-1)+p)%p*phi[k/i]%p)%p;
40         }
41         printf("%d\n",ans);
42     }
43     return 0;
44 }
45 void phi_table(int n){
46     phi[1]=1;
47     for(int i=2;i<=n;i++){
48         if(!notp[i]){
49             prime[++prime[0]]=i;
50             phi[i]=i-1;
51         }
52         for(int j=1;j<=prime[0]&&i*prime[j]<=n;j++){
53             notp[i*prime[j]]=true;
54             if(i%prime[j])phi[i*prime[j]]=phi[i]*(prime[j]-1);
55             else{
56                 phi[i*prime[j]]=phi[i]*prime[j];
57                 break;
58             }
59         }
60     }
61     for(int i=2;i<=n;i++)phi[i]=((long long)i*i%p*phi[i]%p+phi[i-1])%p;
62 }
63 void modify(int x,int d){
64     int k=id[x];
65     while(id[x]==k){
66         sum[x]=(sum[x]+d)%p;
67         x++;
68     }
69     k++;
70     while(k<=cntb){
71         lazy[k]=(lazy[k]+d)%p;
72         k++;
73     }
74 }
75 inline int query(int x){return (sum[x]+lazy[id[x]])%p;}
76 int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
View Code

\begin{align}&\sum_{i=1}^n\sum_{j=1}^n[(i,j)=1]ij\\=&2\left(\sum_{i=1}^n i\sum_{j=1}^i[(i,j)=1]j\right)-1\\=&2\left(\sum_{i=1}^n i^2\frac{\varphi(i)+e(i)}2\right)-1&(e(i)=[i=1])\\=&\sum_{i=1}^n i^2\varphi(i)\end{align}

posted @ 2017-04-13 11:34  AntiLeaf  阅读(267)  评论(0编辑  收藏  举报