結果

問題 No.1952 xooooooooooor
ユーザー umezo
提出日時 2022-05-23 16:23:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 2,099 ms
コンパイル使用メモリ 199,972 KB
最終ジャッジ日時 2025-01-29 14:05:58
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int MOD=998244353;
ll modpow(ll x,ll n){
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x%MOD;
    x=x*x%MOD;
    n/=2;
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,m;
  cin>>n>>m;
  
  if(n==0){
    cout<<0<<endl;
    return 0;
  }
  
  vector<int> A;
  while(n>0){
    A.push_back(n%2);
    n/=2;
  }
  int a=A.size();
  vector<vector<int>> B(a,vector<int> (100));
  rep(i,a) rep(j,a) B[i][j+i]=A[j];
  rep(j,100) rep(i,a-1) B[i+1][j]^=B[i][j];
  ll ans=0;
  if(m<=a){
    rep(i,a+m-1) ans=(ans+B[m-1][i]*modpow(2,i)%MOD)%MOD;
  }
  else{
    rep(i,a-1) ans=(ans+B[a-1][i]*modpow(2,i)%MOD)%MOD;
    rep(i,a-1) ans=(ans+B[a-1][i+a]*modpow(2,i+m)%MOD)%MOD;
    if(B[a-1][a-1]){
      ans=(ans+modpow(2,m))%MOD;
      ans=(ans-modpow(2,a-1)+MOD)%MOD;
    }
  }
  cout<<ans<<endl;

  return 0;
}
0