#include using namespace std; const long long MOD = 998244353; const int LOG = 60; vector> matmul(vector> A, vector> B){ int N = A.size(); vector> C(N, vector(N, 0)); for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ for (int k = 0; k < N; k++){ C[i][k] += A[i][j] * B[j][k]; C[i][k] %= MOD; } } } return C; } vector> matpow(vector> A, long long K){ int N = A.size(); vector> ans(N, vector(N, 0)); for (int i = 0; i < N; i++){ ans[i][i] = 1; } while (K > 0){ if (K % 2 == 1){ ans = matmul(ans, A); } A = matmul(A, A); K /= 2; } return ans; } int main(){ long long N, M; cin >> N >> M; vector POW(LOG); for (int i = 0; i < LOG; i++){ POW[i] = (long long) 1 << i; } vector> S(LOG, vector(2, 0)); for (int i = 0; i < LOG; i++){ long long b = POW[i]; S[i][0] = M / (b * 2) * b + min(M % (b * 2), b); S[i][1] = M / (b * 2) * b + max(M % (b * 2) - b, (long long) 0); S[i][0] %= MOD; S[i][1] %= MOD; } vector> mat(LOG * 2, vector(LOG * 2, 0)); for (int i = 0; i < LOG; i++){ for (int j = 0; j < 2; j++){ for (int k = 0; k < LOG; k++){ for (int l = 0; l < 2; l++){ vector> dp(LOG + 1, vector(2, 0)); dp[LOG][0] = 1; for (int x = LOG - 1; x >= 0; x--){ for (int y = 0; y < 2; y++){ for (int d = 0; d < 2; d++){ if (!(x == i && d == j) && !(x == k && d != l)){ if (!((M >> x & 1) == 0 && y == 0 && d == 1)){ int y2 = y; if ((M >> x & 1) == 1 && d == 0){ y2 = 1; } dp[x][y2] += dp[x + 1][y]; } } } } } long long cnt = dp[0][1] % MOD; mat[i * 2 + j][k * 2 + l] = cnt * (POW[k] % MOD) % MOD; } } } } mat = matpow(mat, N - 2); long long ans = 0; for (int i = 0; i < LOG; i++){ for (int j = 0; j < 2; j++){ for (int k = 0; k < LOG; k++){ for (int l = 0; l < 2; l++){ ans += S[i][j] * (POW[i] % MOD) % MOD * mat[i * 2 + j][k * 2 + l] % MOD * S[k][l ^ 1] % MOD; ans %= MOD; } } } } cout << ans << endl; }