- #include <bits/stdc++.h>
- using namespace std;
- #define llu long long unsigned
- llu a1, b1,c1, a2, b2, c2, f0, f1, f2, g0, g1, g2,n, m, answer1, answer2, MOD;
- llu cm[6][6];
- void mul(llu a[6][6],llu b[6][6]){
- memset(cm, 0, sizeof(cm));
- for(int i = 0; i <6; i++){
- for(int j = 0; j <6; j++){
- for(int k = 0; k <6; k++){
- cm[i][j]+= ((a[i][k]%MOD)*(b[k][j]%MOD))%MOD;
- cm[j][j]%=MOD;
- }
- }
- }
- for(int i = 0; i <6; i++){
- for(int j = 0; j <6; j++){
- a[i][j] = cm[i][j]%MOD;
- }
- }
- }
- void ans(llu p[6][6], llu n){
- llu m[6][6] = {{a1,b1,0,0,0,c1},{1,0,0,0,0,0},{0,1,0,0,0,0}, {0,0,c2,a2,b2,0},{0,0,0,1,0,0},{0,0,0,0,1,0}};
- if(n == 1) return;
- ans(p, n/2);
- mul(p, p);
- if(n%2) mul(p, m);
- }
- int main(){
- int ts;
- scanf("%d", &ts);
- for(int p = 1; p <= ts; p++){
- scanf("%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld", &a1,&b1, &c1, &a2, &b2,&c2, &f0, &f1, &f2,&g0, &g1, &g2, &MOD,&m);
- llu sf[3] = {f0,f1,f2};
- llu sg[3] = {g0,g1,g2};
- printf("Case %d:\n", p);
- for(int i = 1; i <=m; i++){
- llu f[6][6] = {{a1,b1,0,0,0,c1},{1,0,0,0,0,0},{0,1,0,0,0,0}, {0,0,c2,a2,b2,0},{0,0,0,1,0,0},{0,0,0,0,1,0}};
- scanf("%lld", &n);
- if (n<3) answer1 = sf[n]%MOD, answer2 = sg[n]%MOD;
- else ans(f, n-2),answer1 = (f[0][0]*f2+f[0][1]*f1+f[0][2]*f0+f[0][3]*g2+f[0][4]*g1+f[0][5]*g0)%MOD, answer2 = (f[3][0]*f2+f[3][1]*f1+f[3][2]*f0+f[3][3]*g2+f[3][4]*g1+f[3][5]*g0)%MOD;
- printf("%lld %lld\n",answer1%MOD, answer2%MOD);
- }
- }
- return 0;
- }
Wednesday, 26 July 2017
Lightoj 1131 - Just Two Functions
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment