#include #include #include #include using namespace std; const int SIZE=3600; int n,c,p; inline void add(int a[30][30],int b[30][30],int c[30][30]) { for(int i=0;i>=1) { if(b&1) { mul(c,a,t); memcpy(c,t,SIZE); } mul(a,a,t); memcpy(a,t,SIZE); } } int a[30][30],b[30][30],e[30][30]; void f(int a[30][30],int c,int b[30][30]) { if(c==1) { memcpy(b,a,SIZE); return ;} if(c&1) { f(a,c-1,b); int x[30][30]; mul(a,b,x); add(a,x,b); return; } int x[30][30],t[30][30]; f(a,c/2,x); ksm(a,c/2,b); add(e,b,t); mul(t,x,b); } void print(int a[30][30]) { for(int i=0;i