Polynomial / Formal Power Series¶
This lane is about one narrow contest route:
- coefficients live under one NTT-friendly prime modulus
- only the first
ncoefficients matter - and you need algebra on truncated series, not just one plain convolution
The exact first route in this repo is:
- invert one formal power series
A(x)modulox^n - under
998244353 - with Newton doubling and NTT-backed multiplication
This page is not trying to teach all symbolic polynomial algebra at once.
It is teaching the first reusable FPS doorway that later supports:
logexppowsqrt
At A Glance¶
- Use when: the statement literally asks for inverse / log / exp / pow / sqrt of a truncated formal power series, or the intended solution clearly becomes FPS algebra after one convolution layer
- Core worldview: work modulo
x^n, so only the firstncoefficients matter; upgrade one correct prefix of the answer to a longer correct prefix by Newton iteration - Main tools: NTT convolution, truncation modulo
x^n, nonzero constant term, Newton doubling - Typical complexity:
O(n log^2 n)for the inverse route with repeated NTT products - Main trap: treating FPS algebra like ordinary full polynomials and forgetting truncation after every doubling step
Strong contest signals:
- the statement is literally
Inv / Log / Exp / Pow / Sqrt of Formal Power Series - coefficients are modulo
998244353or another NTT-friendly prime - one direct coefficient-by-coefficient DP feels too slow, but convolution-backed Newton steps fit
Strong anti-cues:
- you only need one convolution -> FFT And NTT
- the modulus is not friendly for your NTT route
- the task is really recurrence or combinatorics, not FPS algebra
Prerequisites¶
Helpful neighboring topics:
- Linear Recurrence / Matrix Exponentiation for "coefficient objects under one modulus" instinct
- FFT And NTT when the convolution layer itself still feels less trustworthy than the Newton-doubling wrapper built on top of it
Problem Model And Notation¶
Write
and suppose we only care modulo x^n.
That means:
- coefficients of degree
>= nare irrelevant - every product is truncated to the first
nterms
So when we say
we mean:
The inverse exists exactly when:
That one condition is the entry ticket for the whole first route.
Why Newton Doubling Works¶
Suppose B(x) is already correct modulo x^m:
Then define:
This is the Newton step for multiplicative inverse, and it doubles the number of correct coefficients:
So the contest loop is:
- start with the degree-1 inverse
b_0 = a_0^{-1} - repeatedly double the trusted prefix length
- truncate every intermediate product to the new target length
That is the whole starter route.
Worked Example: Inv Of Formal Power Series¶
In Inv of Formal Power Series, the statement gives:
n- coefficients
a_0, ..., a_{n-1}
and asks for:
This is the cleanest official first rep because:
- the series inverse is the whole task
- the modulus is already the standard NTT prime
- there is no extra modeling noise hiding the FPS layer
Variant Chooser¶
Use Plain FFT / NTT When¶
- the task is only one convolution or polynomial product
- no inverse / log / exp / sqrt / power is required
Use FPS Inverse When¶
- you need
A(x)^{-1} mod x^n a_0 != 0- and repeated truncated products are affordable
Use Wider FPS Algebra Later When¶
- the inverse route already feels natural
- and the task wants:
log F = integral(F' / F)exp Fpow Fsqrt F
This repo's first starter intentionally stops before those larger routes.
Implementation Notes¶
- keep one NTT-backed convolution helper trusted first
- represent the answer prefix as a vector of length
m - on each doubling step, truncate to
min(2m, n) - never forget that all equalities are modulo
x^k, not as full infinite series
The exact in-repo starter keeps the route narrow:
998244353- one FPS inverse
- one Newton doubling loop
Complexity¶
If convolution is O(t log t), then Newton doubling gives:
for the inverse route in contest-ready form.
That is the right mental model for the first lane.
Main Traps¶
- trying FPS before ordinary convolution is trustworthy
- forgetting the condition
a_0 != 0 - forgetting truncation after each doubling step
- assuming the same starter works unchanged for an arbitrary modulus
- overgeneralizing from inverse to
log/exp/powwithout new contracts
Recommended Practice Flow¶
- reopen FFT And NTT if convolution trust is still low
- learn the inverse contract on this page
- implement or reuse the starter
- verify it on Inv of Formal Power Series
- only then reach for
log/exp/pow/sqrt
Reopen Paths¶
- Quick refresher -> Polynomial / FPS hot sheet
- Exact starter ->
fps-inv-newton.cpp - Practice ladder -> Polynomial / Formal Power Series ladder
- Compare point -> FFT And NTT
Sources¶
- Official docs: AtCoder Library Convolution
- Official benchmark: Library Checker - Inv of Formal Power Series
- Official follow-ups: Library Checker - Log of Formal Power Series, Library Checker - Exp of Formal Power Series