单位根反演
之前碰到过两次但是没学
https://acm.hdu.edu.cn/showproblem.php?pid=7013
hdu多校的题
单位根反演都比较套路
如果有组合数可以把常系数和它化成n次幂的形式
实现复杂度从$n/k$变到$k$
详细的有空补
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") //#include <immintrin.h> //#include <emmintrin.h> #include <bits/stdc++.h> using namespace std; #define rep(i,h,t) for (int i=h;i<=t;i++) #define dep(i,t,h) for (int i=t;i>=h;i--) #define ll long long #define me(x) memset(x,0,sizeof(x)) #define IL inline #define rint register int inline ll rd(){ ll x=0;char c=getchar();bool f=0; while(!isdigit(c)){if(c=='-')f=1;c=getchar();} while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();} return f?-x:x; } char ss[1<<24],*A=ss,*B=ss; IL char gc() { return A==B&&(B=(A=ss)+fread(ss,1,1<<24,stdin),A==B)?EOF:*A++; } template<class T>void maxa(T &x,T y) { if (y>x) x=y; } template<class T>void mina(T &x,T y) { if (y<x) x=y; } template<class T>void read(T &x) { int f=1,c; while (c=gc(),c<48||c>57) if (c=='-') f=-1; x=(c^48); while(c=gc(),c>47&&c<58) x=x*10+(c^48); x*=f; } const int mo=1e9+9; ll fsp(ll x,ll y) { if (y==1) return x; ll ans=fsp(x,y/2); ans=ans*ans%mo; if (y%2==1) ans=ans*x%mo; return ans; } struct cp { ll x,y; cp operator +(cp B) { return (cp){x+B.x,y+B.y}; } cp operator -(cp B) { return (cp){x-B.x,y-B.y}; } ll operator *(cp B) { return x*B.y-y*B.x; } int half() { return y < 0 || (y == 0 && x < 0); } }; struct re{ int a,b,c; }; const int g=13; const int N=5e5; ll k,l,n; ll f1[N],f2[N]; ll h[510][510],p[510][510]; struct re2{ ll a[510][510]; void operator *=(const re2 b){ re2 c; me(c.a); rep(i,0,n-1) rep(j,0,n-1) rep(k,0,n-1) c.a[i][k]=(c.a[i][k]+a[i][j]*b.a[j][k])%mo; rep(i,0,n-1) rep(j,0,n-1) a[i][j]=c.a[i][j]; } }a,b,c; int main() { freopen("1.in","r",stdin); ios::sync_with_stdio(false); int T; cin>>T; while (T--) { cin>>k>>l>>n; k=(k-2)%mo; int w=fsp(g,(mo-1)/n); f1[0]=1; rep(i,1,n) f1[i]=f1[i-1]*w%mo; int w1=fsp(w,mo-2); f2[0]=1; rep(i,1,n*n) f2[i]=f2[i-1]*w1%mo; rep(i,0,n-1) rep(j,0,n-1) a.a[i][j]=c.a[i][j]=f2[i*j]; rep(i,0,n-1) rep(j,0,n-1) b.a[i][j]=fsp((f1[i]+f1[j]+k)%mo,l)*fsp(n*n,mo-2)%mo; a*=b; a*=c; rep(i,0,n-1) { rep(j,0,n-2) cout<<a.a[i][j]<<" "; cout<<a.a[i][n-1]<<endl; } } return 0; }