結果

問題 No.1952 xooooooooooor
ユーザー SSRSSSRS
提出日時 2022-05-20 22:39:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,234 bytes
コンパイル時間 1,829 ms
コンパイル使用メモリ 169,396 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 13:26:26
合計ジャッジ時間 2,736 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
int main(){
  long long N, M;
  cin >> N >> M;
  if (N == 0){
    cout << 0 << endl;
  } else if (M <= 29){
    long long ans = 0;
    for (int i = 0; i < M; i++){
      ans ^= N;
      N <<= 1;
    }
    cout << ans << endl;
  } else {
    string S;
    while (N > 0){
      S += '0' + N % 2;
      N /= 2;
    }
    int L = S.size();
    long long ans = 0;
    for (int i = 0; i < L - 1; i++){
      int sum = 0;
      for (int j = 0; j <= i; j++){
        sum += S[j] - '0';
      }
      if (sum % 2 == 1){
        ans += modpow(2, i);
      }
    }
    int cnt = 0;
    for (int i = 0; i < L; i++){
      cnt += S[i] - '0';
    }
    if (cnt % 2 == 1){
      ans += (modpow(2, M - L + 1) - 1) * modpow(2, L - 1) % MOD;
    }
    for (int i = 1; i < L; i++){
      int sum = 0;
      for (int j = i; j < L; j++){
        sum += S[j] - '0';
      }
      if (sum % 2 == 1){
        ans += modpow(2, M - 1 + i);
      }
    }
    ans %= MOD;
    cout << ans << endl;
  }
}
0