File size: 1,118 Bytes
d517dc9
 
 
 
1
2
3
4
5
{"type": "session", "harness": "opencode", "id": "math-0162", "name": "FFT and Number Theoretic Transform"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain FFT for competitive programming"}}
{"type": "message", "message": {"role": "assistant", "content": "FFT: multiply two degree-n polynomials in O(n log n) instead of O(n^2).\nIdea: evaluate at n-th roots of unity (O(n log n) via divide and conquer), multiply pointwise, interpolate back.\nCooley-Tukey: split by even/odd indices, recurse.\nIterative: bit-reverse permutation, then butterfly operations.\n\nNTT: FFT mod prime. Use primitive root g of prime p (e.g., 998244353, g=3). Replace complex roots with g^k mod p.\nAdvantage: exact integer arithmetic, no floating point errors.\n\nApplications:\n- Polynomial multiplication (coefficients = product of input polynomials)\n- String matching: pattern in text via convolution\n- Subset convolution\n- Multiplying large integers\n- Counting problems: ways to sum to target"}}