链接: click here~~
题意:
According to a research, VIM users tend to have shorter fingers, compared with Emacs users.
Hence they prefer problems short, too. Here is a short one:
Given n (1 <= n <= 1018), You should solve for
0 1 2
0 1 42837
代码:
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <math.h> using namespace std; #define LL long long const long long mod1=1e9+7; const long long mod2=222222224; const long long mod3=183120; struct Matrix { long long mapp[2][2]; }; Matrix p= {0,1,1,0}; Matrix p1= {0,1,1,3}; Matrix unin= {1,0,0,1}; Matrix powmul(Matrix a,Matrix b,long long mod) { Matrix c; for(int i=0; i<2; i++) for(int j=0; j<2; j++) { c.mapp[i][j]=0; for(int k=0; k<2; k++) c.mapp[i][j]+=(a.mapp[i][k]*b.mapp[k][j])%mod; c.mapp[i][j]%=mod; } return c; } Matrix powexp(long long n,long long mod) { Matrix m=p1,b=unin; while(n>=1) { if(n&1) b=powmul(b,m,mod); n>>=1; m=powmul(m,m,mod); } return powmul(p,b,mod); } long long T; int main() { while(~scanf("%lld",&T)) { Matrix ans; ans=powexp(T,mod3); ans=powexp(ans.mapp[0][0],mod2); ans=powexp(ans.mapp[0][0],mod1); cout<<ans.mapp[0][0]<<endl; // printf("%lld\n",ans.mapp[0][0]); } return 0; }