Test instructions: BC Round 72 Chinese Noodle
Analysis (official):
If you learn Dirichlet convolution, you know that this thing is g (n) = (f*1^k) (n),
As a result of the binding law, so we quickly power a 1^k on the line.
Of course, the force of the positive and the type can also be engaged (I will not, anyway).
Once the Dirichlet convolution complexity is O (NLOGN), the total time complexity is O (NLOGNLOGK).
Note: Popularize the concept of Dirichlet convolution, set f,g as two number theoretic functions,
Then the Regulation (F∗G) =∑D|NF (d) g (N/D) is f,g Dirichlet convolution
Dirichlet convolution has the following properties, there are commutative laws and binding laws, and there are distributive laws for addition.
f∗ (g∗h) = (f∗g) ∗h
f∗ (g+h) =f∗g+f∗h
F∗g=g∗f
And then for this one of the Dirichlet convolution is O (nlogn) This I do not understand
But look at the online great God write estimates are similar, feeling and the complexity of the sieve is almost even smaller should be in O (Nlognlogn) around
So the complexity of the following code should probably be O (nlog^2nlogk)
Then incidentally, for the Dirichlet convolution, there is a single-element E.
namely: F*e=f,
This unitary function has a property e[1]=1,e[k]=0,k=1,2,3 ...
This will be used when the power is fast.
And then on the code
#include <iostream>#include<cstdio>using namespaceStd;typedefLong LongLL;Const intn=1e5+5;ConstLL mod=1e9+7;intn,k; LL F[n],s[n],ans[n],tmp[n];voidsolve () { while(k) {if(k&1) { for(intI=1; i<=n; ++i) tmp[i]=0; for(intI=1; i*i<=n; ++i) {tmp[i*i]= (Tmp[i*i]+ans[i]*s[i])%MoD; for(intj=i+1; j*i<=n; ++j) Tmp[i*j]+= (Ans[i]*s[j]%mod+ans[j]*s[i]%mod)%mod,tmp[i*j]%=MoD; } for(intI=1; i<=n; ++i) ans[i]=Tmp[i]; } for(intI=1; i<=n; ++i) tmp[i]=0; for(intI=1; i*i<=n; ++i) {tmp[i*i]= (Tmp[i*i]+s[i]*s[i])%MoD; for(intj=i+1; j*i<=n; ++j) Tmp[i*j]+= (S[i]*s[j]%mod+s[j]*s[i]%mod)%mod,tmp[i*j]%=MoD; } for(intI=1; i<=n;++i) s[i]=Tmp[i]; K>>=1; } for(intI=1; i<=n; ++i) tmp[i]=0; for(intI=1; i*i<=n; ++i) {tmp[i*i]= (Tmp[i*i]+f[i]*ans[i])%MoD; for(intj=i+1; j*i<=n; ++j) Tmp[i*j]+= (F[i]*ans[j]%mod+f[j]*ans[i]%mod)%mod,tmp[i*j]%=MoD; } for(intI=1; i<=n;++i) ans[i]=tmp[i];}intMain () {intT; scanf ("%d",&T); while(t--) {scanf ("%d%d",&n,&k); for(intI=1; i<=n; ++i) scanf ("%i64d", &f[i]), s[i] =1, ans[i] =0; ans[1] =1; Solve (); for(intI=1; i<n; ++i) printf ("%i64d", Ans[i]); printf ("%i64d\n", Ans[n]); } return 0;}
View Code
HDU 5628 Clarke and math Dirichlet convolution + fast power