Links: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=46252
The silly matrix accelerates. QwQ
#include <cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#defineLL Long Long#defineMoD 1000000007using namespacestd; LL N;intax, ay, A0, BX, by, B0, Qwq;structmatrix{ints[5][5]; voidClear () {memset (s),0,sizeof(s)); }}ans, A;intMulintAintb) {//cout<<a<< "" <<b<< "" <<a*b%mod<<endl; return(int) (ll) ((LL) * (LL) b)%mod);} Matrixoperator*(matrix A, matrix B) {matrix C; C.clear (); for(inti =0; I <=4; i++){ for(intj =0; J <=4; J + +){ for(intK =0; K <=4; k++) {C.s[i][j]= (C.s[i][j] + mul (a.s[i][k], b.s[k][j])%MoD; } } } returnC;} voidReset () {n--; Ans.clear (); A.clear (); ans.s[0][0] =1; ans.s[0][1] = a0; ans.s[0][2] = B0; ans.s[0][3] = ans.s[0][4] =Mul (a0, B0); a.s[0][0] =1; a.s[0][1] = ay; a.s[1][1] =Ax; a.s[0][2] = by; a.s[2][2] =BX; a.s[0][3] = a.s[0][4] =Mul (ay, by); a.s[1][3] = a.s[1][4] =mul (ax, by); a.s[2][3] = a.s[2][4] =mul (bx, ay); a.s[3][3] = a.s[3][4] =mul (AX, BX); a.s[4][4] =1; while(n) {if(n&1) ans = ans *A; A= A *A; N>>=1; }}intMain () { while(~SCANF ("%lld", &N)) {scanf ("%d%d%d\n%d%d%d", &a0, &ax, &ay, &b0, &BX, &by ); if(n = =0) {printf ("0\n");Continue; } Reset (); printf ("%d\n", ans.s[0][4]); } return 0;}
View Code
"HDU4686" ARC of the Dream