結果

問題 No.2060 AND Sequence
ユーザー butsurizukibutsurizuki
提出日時 2022-08-26 21:54:59
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,996 bytes
コンパイル時間 2,773 ms
コンパイル使用メモリ 253,848 KB
実行使用メモリ 11,840 KB
最終ジャッジ日時 2023-08-04 01:23:56
合計ジャッジ時間 4,618 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,620 KB
testcase_01 AC 9 ms
11,556 KB
testcase_02 AC 8 ms
11,560 KB
testcase_03 AC 9 ms
11,572 KB
testcase_04 AC 8 ms
11,840 KB
testcase_05 AC 9 ms
11,548 KB
testcase_06 AC 8 ms
11,568 KB
testcase_07 AC 8 ms
11,620 KB
testcase_08 AC 9 ms
11,624 KB
testcase_09 AC 8 ms
11,688 KB
testcase_10 AC 8 ms
11,552 KB
testcase_11 AC 8 ms
11,636 KB
testcase_12 AC 9 ms
11,632 KB
testcase_13 AC 8 ms
11,628 KB
testcase_14 AC 9 ms
11,620 KB
testcase_15 AC 8 ms
11,560 KB
testcase_16 AC 8 ms
11,676 KB
testcase_17 AC 9 ms
11,572 KB
testcase_18 AC 8 ms
11,568 KB
testcase_19 AC 8 ms
11,620 KB
testcase_20 AC 8 ms
11,564 KB
testcase_21 AC 8 ms
11,628 KB
testcase_22 AC 8 ms
11,556 KB
testcase_23 AC 9 ms
11,576 KB
testcase_24 AC 8 ms
11,816 KB
testcase_25 AC 9 ms
11,800 KB
testcase_26 AC 8 ms
11,620 KB
testcase_27 AC 9 ms
11,636 KB
testcase_28 AC 8 ms
11,564 KB
testcase_29 AC 9 ms
11,572 KB
testcase_30 AC 8 ms
11,560 KB
testcase_31 AC 9 ms
11,692 KB
testcase_32 AC 8 ms
11,692 KB
testcase_33 AC 8 ms
11,568 KB
testcase_34 AC 8 ms
11,636 KB
testcase_35 AC 9 ms
11,752 KB
testcase_36 AC 8 ms
11,624 KB
testcase_37 AC 8 ms
11,552 KB
testcase_38 AC 8 ms
11,564 KB
testcase_39 AC 9 ms
11,564 KB
testcase_40 AC 8 ms
11,564 KB
testcase_41 AC 9 ms
11,576 KB
testcase_42 AC 8 ms
11,556 KB
testcase_43 AC 9 ms
11,636 KB
testcase_44 AC 9 ms
11,752 KB
testcase_45 AC 9 ms
11,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

#define mod 998244353
long long power(long long a,long long b){
  long long x=1,y=a;
  while(b>0){
    if(b&1ll){
      x=(x*y)%mod;
    }
    y=(y*y)%mod;
    b>>=1;
  }
  return x%mod;
}

long long modular_inverse(long long n){
  return power(n,mod-2);
}

long long factorial[524288];
long long invfact[524288];

void cfact(){
  long long i;
  factorial[0]=1;
  factorial[1]=1;
  for(i=2;i<524288;i++){
    factorial[i]=factorial[i-1]*i;
    factorial[i]%=mod;
  }
  invfact[524287]=modular_inverse(factorial[524287]);
  for(i=524286;i>=0;i--){
    invfact[i]=invfact[i+1]*(i+1);
    invfact[i]%=mod;
  }
}

long long calcnCr(long long n,long long k){
  if(k<0 || n<k){return 0;}
  return (factorial[n]*((invfact[k]*invfact[n-k])%mod))%mod;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cfact();

  long long n,m;
  cin >> n >> m;

  vector<vector<long long>> dp(31,vector<long long>(2,0));
  dp[0][1]=1;
  for(int tg=29;tg>=0;tg--){
    vector<vector<long long>> ndp(31,vector<long long>(2,0));
    for(int i=0;i<=30;i++){
      for(int j=0;j<2;j++){
        if(dp[i][j]==0){continue;}
        if(m&(1ll<<tg)){
          if(j==1){
            ndp[i][0]+=dp[i][j];
            ndp[i][0]%=mod;
            ndp[i+1][1]+=dp[i][j];
            ndp[i+1][1]%=mod;
          }
          else{
            ndp[i][j]+=dp[i][j];
            ndp[i][j]%=mod;
            ndp[i+1][j]+=dp[i][j];
            ndp[i+1][j]%=mod;
          }
        }
        else{
          if(j==1){
            ndp[i][j]+=dp[i][j];
            ndp[i][j]%=mod;
          }
          else{
            ndp[i][j]+=dp[i][j];
            ndp[i][j]%=mod;
            ndp[i+1][j]+=dp[i][j];
            ndp[i+1][j]%=mod;
          }
        }
      }
    }
    dp=ndp;
  }

  long long res=0;
  for(int i=0;i<=30;i++){
    for(int j=0;j<2;j++){
      long long ce=power(n,i);
      res+=dp[i][j]*ce;
      res%=mod;
    }
  }
  cout << res << "\n";
  return 0;
}
0