Link: click here~~
Test instructions
According to a, the VIM users tend to the shorter fingers, compared with Emacs users.
Hence They prefer problems short, too. Here are a short one:
Given N (1 <= n <= 1018), you should solve for
G (g (n)) MoD 109 + 7
where
G (N) = 3g (n-1) + g (n-2)
G (1) = 1
G (0) = 0
Input There is several test cases. For the test case, there is an integer n-a single line.
Please process until EOF (End of File).
Output for each test case, "print a single" With a integer, the corresponding answer
Sample Input
012
Sample Output
0142837
"Problem-solving ideas" specific reference to the previous blog, basically the same idea: click here
Code:
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include < math.h>using namespace std; #define LL Long Longconst long Mod1=1e9+7;const long Mod2=222222224;const long lon G 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;}
HDU 4291 A Short problem (2012 All network races, matrix fast Power + Cycle section)