algo — C++23 日本語リファレンス GitHub

test/yosupo/math/find_linear_recurrence.test.cpp

AC · 最終更新 2026-09-07 · GitHub

問題: https://judge.yosupo.jp/problem/find_linear_recurrence

依存するヘッダ(4)
実装
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/find_linear_recurrence
#include <iostream>
#include <vector>
#include "linalg/berlekamp_massey.hpp"
#include "number_theory/modint.hpp"

using Mint = modint998;

int main() {
    int n;
    std::cin >> n;
    std::vector<Mint> a(n);
    for (int i = 0; i < n; ++i) std::cin >> a[i];
    auto c = berlekamp_massey(a);
    const int d = c.size();
    std::cout << d << '\n';
    for (int i = 0; i < d; ++i) std::cout << c[i] << " \n"[i + 1 == d];
    if (d == 0) std::cout << '\n';
    return 0;
}