結果

問題 No.3172 三角関数べき乗のフーリエ級数展開
ユーザー tnakao0123
提出日時 2025-06-07 17:28:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 2,107 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 58,192 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-06-07 17:28:43
合計ジャッジ時間 1,773 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:83:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   83 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3172.cc:  No.3172 荳芽ァ帝未謨ー縺ケ縺堺ケ励・繝輔・繝ェ繧ィ邏壽焚螻暮幕 - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MOD = 998244353;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
  MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }

  explicit operator int() const { return v; }
  
  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator-() const { return MI(MOD - v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

using mi = MI<MOD>;
using vmi = vector<mi>;

/* global variables */

vmi fs, invfs;
mi bs[MAX_N + 1];

/* subroutines */

inline mi nck(int n, int k) {  // nCk % MOD
  if (n < k || k < 0) return 0;
  return fs[n] * invfs[n - k] * invfs[k];
}

void prepare_fracs(int n) {
  fs.resize(n + 1), invfs.resize(n + 1);
  fs[0] = invfs[0] = 1;
  for (int i = 1; i <= n; i++) {
    fs[i] = fs[i - 1] * i;
    invfs[i] = fs[i].inv();
  }
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  prepare_fracs(n);
  
  for (int i = -n; i <= n; i++)
    if (! ((n + i) & 1))
      bs[abs(i)] += nck(n, (n + i) / 2);

  for (int i = 0; i <= n; i++)
    printf("%d%c", (int)bs[i], (i < n) ? ' ' : '\n');
    
  return 0;
}
0