MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / inv

Function inv

code/mathematics/ntt.cpp:35–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33 Num ni = Num(n).inv();
34 rep(i,0,n) { x[i] = x[i] * ni; } } }
35void inv(Num x[], Num y[], int l) {
36 if (l == 1) { y[0] = x[0].inv(); return; }
37 inv(x, y, l>>1);
38 // NOTE: maybe l<<2 instead of l<<1
39 rep(i,l>>1,l<<1) T1[i] = y[i] = 0;
40 rep(i,0,l) T1[i] = x[i];
41 ntt(T1, l<<1); ntt(y, l<<1);
42 rep(i,0,l<<1) y[i] = y[i]*2 - T1[i] * y[i] * y[i];
43 ntt(y, l<<1, true); }
44void sqrt(Num x[], Num y[], int l) {
45 if (l == 1) { assert(x[0].x == 1); y[0] = 1; return; }
46 sqrt(x, y, l>>1);

Callers 1

sqrtFunction · 0.85

Calls 2

nttFunction · 0.85
invMethod · 0.80

Tested by

no test coverage detected