#include #include using namespace std; // 2x2の行列を表現するための型エイリアス using Matrix = vector>; // 行列の積を計算する関数 Matrix mul(const Matrix& a, const Matrix& b) { Matrix c(2, vector(2, 0)); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { c[i][j] += a[i][k] * b[k][j]; } } } return c; } // 2つの行列がmod 67で合同か判定する関数 bool func(const Matrix& a, const Matrix& b) { for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { // PythonとC++の負の数の剰余計算の挙動の違いを吸収 int mod_a = ((a[i][j] % 67) + 67) % 67; int mod_b = ((b[i][j] % 67) + 67) % 67; if (mod_a != mod_b) { return false; } } } return true; } int main() { // 入力の高速化 ios_base::sync_with_stdio(false); cin.tie(NULL); // 行列Aの入力 Matrix A(2, vector(2)); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { cin >> A[i][j]; } } // 行列Bの入力 Matrix B(2, vector(2)); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { cin >> B[i][j]; } } // Pの各要素を全探索 for (int p11 = 0; p11 < 67; ++p11) { for (int p12 = 0; p12 < 67; ++p12) { for (int p21 = 0; p21 < 67; ++p21) { for (int p22 = 0; p22 < 67; ++p22) { // 行列式が0の場合はスキップ if (p11 * p22 - p12 * p21 == 0) { continue; } Matrix P = {{p11, p12}, {p21, p22}}; Matrix PA = mul(P, A); Matrix BP = mul(B, P); if (func(PA, BP)) { cout << "Yes\n"; return 0; // Pythonのexit()に相当 } } } } } cout << "No\n"; return 0; }