#include #include #include #include #include #include using namespace std; #define maxn 10010 typedef long long LL; int prime[maxn]; mappika; void Prime(){ memset(prime,0,sizeof(prime)); for(int i=2;i=mod){ ans.m[i][j]-=mod; } } } } return ans; } void init(){ memset(E.m,0,sizeof(E.m)); memset(D.m,0,sizeof(D.m)); D.m[0][0]=D.m[0][1]=D.m[1][0]=1; for(int i=0;i<2;i++){ E.m[i][i]=1; } Prime(); } Matrix Pow(Matrix A,LL e,LL mod){ Matrix ans=E; while(e){ if(e&1){ ans=Multi(ans,A,mod); } A=Multi(A,A,mod); e>>=1; } return ans; } LL Pow(LL a,LL b,LL mod){ LL ans=1; while(b){ if(b&1){ ans=(ans*a)%mod; } a=(a*a)%mod; b>>=1; } return ans; } int legendre(LL a,LL p){ if(Pow(a,(p-1)>>1,p)==1){ return 1; } else{ return -1; } } int f0=1,f1=1; LL get_fib(LL n,LL mod) { if(mod==1) return 0; return Pow(D,n,mod).m[0][0]%mod; } LL fac[maxn],GG[maxn]; LL G(LL p) { if(p=0;i--){ n=get_fib(n,loop[i]); } printf("Case #%d: %I64d\n",++cas,n); } return 0; }