.article-info-tag,button{text-transform:uppercase}.day,.postMeta,.postSticky{position:relative}.postTitle a:link,html{-webkit-tap-highlight-color:transparent}#blog-calendar,.code-copay-btn,.code-hljs-len,.hidden{visibility:hidden}#EntryTag,#blogTitle h1{margin-top:20px}#EntryTag a,.postSticky{background:#6fa3ef}#blogTitle h1 a:hover,.dayTitle a,a,a:active,a:link,a:visited{color:#5c8ec6}#calendar table a:hover,#navList a:hover,.postDesc a:hover,a:active,a:hover,a:link,a:visited,button{text-decora…ryTag a:visited{color:#666}#BlogPostCategory a,#EntryTag a{height:20px;line-height:20px;color:#fff!important;padding:3px 5px;border-radius:3px;margin:2px 5px 0;text-decoration:none;font-size:14px}#BlogPostCategory a:hover,#EntryTag a:hover{transition:all .3s linear 0s;opacity:.8}#topics .postDesc{padding-left:0;width:100%;text-align:left;color:#666;margin-top:5px;background:0 0}.feedbackListSubtitle-louzhu:after,.feedbackListSubtitle:after,.feedbackListSubtitle:before{top:11px;right:100%;left:-1

Luogu P5264 多项式三角函数

\(\mathtt{Description}\)

给定 \(\deg = n\) 的多项式 \(f\)\(\text{type}\),求一个多项式 \(g\) 使得

\[g\equiv \sin f \pmod {998244353}\quad(\text{type}=0) \]

\[g\equiv \cos f \pmod {998244353}\quad(\text{type}=1) \]

\(\mathtt{restrictions:}1\leq n \le10^5,a_i\in[0,998244353)\cap \mathbb{N}\)

\(\mathtt{Solution}\)

奇怪的多项式模板增加了!

\(\mathtt{Pre\;Knowledge}\)

  • 多项式 \(\exp\)
  • 欧拉公式

\(\mathtt{Main\;Body}\)

我们知道欧拉公式

\[e^{ix} = \cos x+ i\sin x \]

\[e^{-ix} = \cos x -i\sin x \]

\[\cos x=\dfrac {e^{ix}+e^{-ix}} {2} \]

\[\sin x = \dfrac{e^{ix}-e^{-ix}}{2i} \]

又有

\[i\equiv86583718\pmod{998244353} \]

所以只需要一个多项式 \(\exp\) 就可以了。

\(\mathtt{Code}\)

  inline auto Cos(vector <int> f) {
    const int len = f.size() ;
    for (int i = 0; i < len; ++i) f[i] = 1ll * f[i] * I % mod ;
    auto g = Exp(f),h = Inv(g) ;
    for (int i = 0; i < len; ++i) g[i] = 1ll * I2 * (g[i] + h[i]) % mod ;
    return g ;  
  }

  inline auto Sin(vector <int> f) {
    const int len = f.size() ;
    for (int i = 0; i < len; ++i) f[i] = 1ll * f[i] * I % mod ;
    auto g = Exp(f),h = Inv(g) ;
    const int x = ksm(I << 1) ;
    for (int i = 0; i < len; ++i) g[i] = 1ll * x * (g[i] - h[i] + mod) % mod ;
    return g ;
  }
posted @ 2021-07-21 11:06  feicheng  阅读(27)  评论(0编辑  收藏  举报