vector<vector<int>> operator*(const vector<vector<int>>& A, const vector<vector<int>>& B) { int n = A.size(); vector<vector<int>> ans(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { longlong temp = (longlong)A[i][j] * B[j][k] % MOD; ans[i][k] = (temp + ans[i][k]) % MOD; } } } return ans; }
vector<vector<int>> fast_pow(vector<vector<int>> &x, int y) { vector<vector<int>> ans(x.size(), vector<int>(x.size(), 0)), xx(x); for (int i = 0; i < x.size(); i++) ans[i][i] = 1; while (y) { if (y & 1) ans = ans * xx; xx = xx * xx; y >>= 1; } return ans; }
intmain(){ int n, m; cin >> n >> m; vector<vector<int>> src(n, vector<int>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> src[i][j]; } } auto ans = fast_pow(src, m); for (auto& arr : ans) { for (auto& i : arr) cout << i << ' '; cout << endl; } return0; }
intget_digs(ll src){ int ans = 0; do ans++; while (src /= 10); return ans; }
ll get_r(ll src, int digs){ ll ans = 0; vector<int> nums; for (int i = 0; i < digs; i++) { nums.push_back(src % 10); src /= 10; } ll base = 1; for (int i = nums.size() - 1; i >= 0; i--, base *= 10) { ans += nums[i] * base; } return ans; }
ll get_l(ll src, int digs){ ll ans = 0; vector<int> nums; for (int i = 0; i < digs; i++) { nums.push_back(src % 10); src /= 10; } sort(nums.begin(), nums.end(), greater<int>()); ll base = 1; for (int i = nums.size() - 1; i >= 0; i--, base *= 10) { ans += nums[i] * base; } return ans; }
intmain(){ ll n; while (cin >> n) { int digs = get_digs(n); vector<ll> nums{n}; set <ll> s{n}; ll l = get_l(n, digs), r = get_r(l, digs), cur = l - r; while (!s.count(cur)) { nums.push_back(cur); s.insert(cur); l = get_l(cur, digs), r = get_r(l, digs), cur = l - r; } int i = 0; while (i < nums.size() && nums[i] != cur) i++; for (; i < nums.size(); i++) { cout << nums[i] << ' '; } cout << endl; } return0; }