結果

問題 No.1952 xooooooooooor
ユーザー ntudantuda
提出日時 2022-06-03 16:43:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 81,748 KB
実行使用メモリ 53,472 KB
最終ジャッジ日時 2023-10-21 01:30:38
合計ジャッジ時間 2,845 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,472 KB
testcase_01 AC 37 ms
53,472 KB
testcase_02 AC 38 ms
53,472 KB
testcase_03 AC 38 ms
53,472 KB
testcase_04 AC 38 ms
53,472 KB
testcase_05 AC 38 ms
53,472 KB
testcase_06 AC 39 ms
53,472 KB
testcase_07 AC 38 ms
53,472 KB
testcase_08 AC 38 ms
53,472 KB
testcase_09 AC 38 ms
53,472 KB
testcase_10 AC 39 ms
53,472 KB
testcase_11 AC 37 ms
53,472 KB
testcase_12 AC 37 ms
53,472 KB
testcase_13 AC 38 ms
53,472 KB
testcase_14 AC 38 ms
53,472 KB
testcase_15 AC 38 ms
53,472 KB
testcase_16 AC 38 ms
53,472 KB
testcase_17 AC 38 ms
53,472 KB
testcase_18 AC 37 ms
53,472 KB
testcase_19 AC 38 ms
53,472 KB
testcase_20 AC 38 ms
53,472 KB
testcase_21 AC 38 ms
53,472 KB
testcase_22 AC 38 ms
53,472 KB
testcase_23 AC 37 ms
53,472 KB
testcase_24 AC 39 ms
53,472 KB
testcase_25 AC 39 ms
53,472 KB
testcase_26 AC 38 ms
53,472 KB
testcase_27 AC 39 ms
53,472 KB
testcase_28 AC 39 ms
53,472 KB
testcase_29 AC 39 ms
53,472 KB
testcase_30 AC 38 ms
53,472 KB
testcase_31 AC 38 ms
53,472 KB
testcase_32 AC 38 ms
53,472 KB
testcase_33 AC 38 ms
53,472 KB
testcase_34 AC 38 ms
53,472 KB
testcase_35 AC 38 ms
53,472 KB
testcase_36 AC 38 ms
53,472 KB
testcase_37 AC 37 ms
53,472 KB
testcase_38 AC 37 ms
53,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

N, M = map(int, input().split())
n = N
NB = []
while n > 0:
    NB.append(n & 1)
    n >>= 1
x = len(NB)
if x > M:
    # 計算量が大きくならない理由
    # x <= 30、 x >= M
    #  よって y < 60 なので下のfor文を回しても問題ない
    y = x + M - 1
    ans = 0
    b = 1
    for i in range(y):
        start = max(0, i - M + 1)
        end = min(i, x) + 1
        a = sum(NB[start:end]) & 1
        ans += a * b
        ans %= MOD
        #print(i,a,b,a*b)
        b <<= 1
else:
    # x-1桁目まで
    ans = 0
    b = 1
    for i in range(x-1):
        start = 0
        end = i + 1
        a = sum(NB[start:end]) & 1
        ans += a * b
        b <<= 1

    # x桁目~ M桁目まで
    ans += (sum(NB) & 1) * (pow(2, M - x+1, MOD)-1) * pow(2, x-1, MOD) % MOD

    # M+1桁 ~ x+M+1桁目まで
    b = pow(2,M,MOD)
    for i in range(x - 1):
        start = i + 1
        end = x + 1
        a = sum(NB[start:end]) & 1
        ans += a * b
        ans %= MOD
        b <<= 1

print(ans)
0