結果

問題 No.1952 xooooooooooor
ユーザー tomerun
提出日時 2022-05-20 22:49:49
言語 Crystal
(1.14.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 653 bytes
コンパイル時間 13,663 ms
コンパイル使用メモリ 296,484 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-20 09:11:24
合計ジャッジ時間 14,761 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353i64
n, m = read_line.split.map(&.to_i)
ans = 0i64
if m <= 30
  m.times do |i|
    ans ^= (n.to_i64 << i)
  end
  puts ans % MOD
  exit
end
all = 0i64
29.times do |i|
  all ^= n.bit(i)
  ans += all * (1i64 << i)
end
all ^= n.bit(29)
ans %= MOD
upper = pow(2i64, m)
if all == 1
  ans += upper - pow(2i64, 29)
  if ans < 0
    ans += MOD
  end
  ans %= MOD
end
29.times do |i|
  all ^= n.bit(i)
  ans += all * upper
  ans %= MOD
  upper *= 2
  upper %= MOD
end
puts (ans + MOD) % MOD

def pow(v, p)
  ret = 1i64
  while p > 0
    if (p & 1i64) != 0
      ret *= v
      ret %= MOD
    end
    v *= v
    v %= MOD
    p >>= 1
  end
  ret
end
0