/* -*- coding: utf-8 -*- * * 3224.cc: No.3224 2テ・陦悟・蜈・髢€ - yukicoder */ #include #include using namespace std; /* constant */ /* typedef */ using ll = long long; template struct Mat2 { T a, b, c, d; Mat2(): a(), b(), c(), d() {} Mat2(T _a, T _b, T _c, T _d): a(_a), b(_b), c(_c), d(_d) {} static Mat2 unit() { return Mat2(1, 0, 0, 1); } static Mat2 read() { int w, x, y, z; scanf("%d%d%d%d", &w, &x, &y, &z); return Mat2(w, x, y, z); } Mat2 operator*(const Mat2 &e) const { return Mat2(a * e.a + b * e.c, a * e.b + b * e.d, c * e.a + d * e.c, c * e.b + d * e.d); } Mat2 operator^(int b) const { Mat2 p = Mat2::unit(); Mat2 a = *this; while (b > 0) { if (b & 1) p = p * a; a = a * a; b >>= 1; } return p; } }; using mat2 = Mat2; /* global variables */ /* subroutines */ /* main */ int main() { mat2 ma = mat2::read(); mat2 mb = mat2::read(); mat2 mc = (ma * mb) ^ 2; printf("%lld %lld\n%lld %lld\n", mc.a, mc.b, mc.c, mc.d); return 0; }