【模板】数学

数学

组合数学

  • Lucas 定理

素数 \(p\)\(\displaystyle{n\choose m}\equiv{\lfloor n/p\rfloor\choose\lfloor m/p\rfloor}{n\bmod p\choose m\bmod p}\pmod p\)

  • exLucas

数论

打表

\(\omega\) 为不同质因子个数,\(d\) 为约数个数

\(n\le\) \(10^1\) \(10^2\) \(10^3\) \(10^4\) \(10^5\) \(10^6\) \(10^7\) \(10^8\) \(10^9\)
\(\max\{\omega(n)\}\) \(2\) \(3\) \(4\) \(5\) \(6\) \(7\) \(8\) \(8\) \(9\)
\(\max\{d(n)\}\) \(4\) \(12\) \(32\) \(64\) \(128\) \(240\) \(448\) \(768\) \(1344\)
\(n\le\) \(10^{10}\) \(10^{11}\) \(10^{12}\) \(10^{13}\) \(10^{14}\) \(10^{15}\) \(10^{16}\) \(10^{17}\) \(10^{18}\)
\(\max\{\omega(n)\}\) \(10\) \(10\) \(11\) \(12\) \(12\) \(13\) \(13\) \(14\) \(15\)
\(\max\{d(n)\}\) \(2304\) \(4032\) \(6720\) \(10752\) \(17280\) \(26880\) \(41472\) \(64512\) \(103680\)

计算几何

  • 平面最近点对

设最近点对距离为 \(d\),则任意 \(\frac{d}{2}\times\frac{d}{2}\) 的正方形内只有一个点

struct Point {
	LL x,y;
	Point(int x=0,int y=0):x(x),y(y){}
	bool operator < (const Point &b) const { return x!=b.x?x<b.x:y<b.y; }
};
LL sq(LL x) { return x*x; }
LL dis(const Point &a,const Point &b) { return sq(a.x-b.x)+sq(a.y-b.y); }

const int N = 4e5+5;
int n;
Point a[N];

void MAIN() {
	cin>>n; For(i,1,n) cin>>a[i].x>>a[i].y;
	sort(a+1,a+n+1);
	LL d = 1e18;
	auto cmp=[](const Point &a,const Point &b)
		{ return a.y!=b.y?a.y<b.y:a.x!=b.x; };
	set<Point,decltype(cmp)> s(cmp);
	For(i,1,n, j = 1) {
		while( sq(a[i].x-a[j].x) >= d ) s.erase(a[j++]);
		for(auto j = s.lower_bound(a[i]); j != s.end() && sq(j->y-a[i].y) < d; ++j)
			ckmin(d, dis(a[i],*j));
		for(auto j = s.lower_bound(a[i]); j != s.begin() && sq(a[i].y-(--j)->y) < d;)
			ckmin(d, dis(a[i],*j));
		s.emplace(a[i]);
	}
	cout<<d<<'\n';
}
  • 二维
using LD = long double;
const LD eps = 1e-8, pi = M_PIl, inf = 1e9;
int sgn(LD x,LD y=0) { return x<y-eps ? -1 : x>y+eps ? 1 : 0; }
struct Point {
    LD x,y; Point(LD x=0,LD y=0):x(x),y(y){}
    Point operator + (const Point &b) const { return {x+b.x,y+b.y}; }
    Point operator - (const Point &b) const { return {x-b.x,y-b.y}; }
    Point operator * (LD k) const { return {k*x,k*y}; }
    Point operator / (LD k) const { return {x/k,y/k}; }
    LD operator ^ (const Point &b) const { return x*b.x+y*b.y; } // 点乘
    LD operator & (const Point &b) const { return x*b.y-y*b.x; } // 叉乘
    bool operator < (const Point &b) const { return sgn(x,b.x)?x<b.x:sgn(y,b.y)<0; }
    bool operator == (const Point &b) const { return !sgn(x,b.x) && !sgn(y,b.y); }
    LD len() { return hypot(x,y); }
    LD len2() { return x*x+y*y; }
    LD ang() { return atan2(y,x); } // (-pi,pi]
    Point rotate(LD k) { return {x*cos(k)-y*sin(k),x*sin(k)+y*cos(k)}; } // 逆时针旋转
};
using VP = vector<Point>;
struct Line {
    Point p,v; LD ang;
	Line(){} Line(Point a,Point b) { p = a, v = b-a, ang = v.ang(); }
	bool operator < (const Line &b) const { return ang < b.ang; }
	bool right(const Point &a) { return sgn(a-p&v) > 0; } // 判断点在直线右侧
	Point ins(const Line &b) { return p + v * (b.v&p-b.p)/(v&b.v); } // 交点
};
using VL = vector<Line>;
//////////////////////////////// 凸包
VP andrew(VP a) { // 建凸包
    VP s;
    int n = 1;
    auto push=[&](const Point &p) {
        while( sz(s)>n && sgn(p-s[sz(s)-2]&s[sz(s)-1]-s[sz(s)-2])<=0 ) s.pop_back();
        s.pb(p);
    };
    sort(all(a)); Rep(i,0,sz(a)) push(a[i]); n = sz(s); rFor(i,sz(a)-1,0) push(a[i]);
	// s.front() == s.back()
	if( sz(s) > 3 && sgn(s[1]-s[0]&s[2]-s[0]) < 0 ) reverse(all(s)); // 逆时针
    return s;
}
LD area(const VP &a) // 面积
	{ LD res=0; Rep(i,0,sz(a)) res += a[i]&a[(i+1)%sz(a)]; return res/2; }
LD diameter(const VP &a) { // 旋转卡壳求直径
	LD res = 0;
	Rep(i,0,sz(a)-1, j = 2) {
		auto area=[](const Point &a,const Point &b,const Point &c)
			{ return fabs(a-b&a-c); };
		while( sgn(area(a[i],a[i+1],a[j]),area(a[i],a[i+1],a[j+1])) < 0 )
			(++j) %= sz(a)-1;
		ckmax(res, max((a[i]-a[j]).len(),(a[i+1]-a[j]).len()));
	}
	return res;
}
VP halfplane(VL a) { // 半平面交
	a.pb(Point(-inf,-inf),Point(inf,-inf)),
	a.pb(Point(inf,-inf),Point(inf,inf)),
	a.pb(Point(inf,inf),Point(-inf,inf)),
	a.pb(Point(-inf,inf),Point(-inf,-inf));
	sort(all(a),[](const Line &x,const Line &y){return x.ang<y.ang;});
	VP p(sz(a)); VL q(sz(a)); int l = 0, r = 0;
	q[0] = a[0];
	Rep(i,1,sz(a)) {
		while( l < r && a[i].right(p[r]) ) --r;
		while( l < r && a[i].right(p[l+1]) ) ++l;
		q[++r] = a[i];
		if( !sgn(q[r].v&q[r-1].v) ) {
			if( sgn(q[r].ang,q[r-1].ang) ) return {};
			if( a[i].right(q[--r].p) ) q[r] = a[i];
		}
		if( l < r ) p[r] = q[r].ins(q[r-1]);
	}
	while( l < r && q[l].right(p[r]) ) --r;
	if( l == r ) return {};
	return p[l] = q[l].ins(q[r]), VP(p.begin()+l,p.begin()+r+1);
}
  • 正弦定理

\(R\) 为外接圆半径,\(\displaystyle\frac{a}{\sin A}=\frac{b}{\sin B}=\frac{c}{\sin C}=2R\)

  • 余弦定理 \(a^2=b^2+c^2-2bc\cos A\)

  • 欧拉公式

顶点数 \(V\),边数 \(E\),面数 \(F\)\(V-E+F=2\)

  • Pick 定理

顶点均为整点的简单多边形,面积 \(A\),内部整点数 \(i\),边界整点数 \(b\)\(A=i+\frac{b}{2}-1\)

多项式

拉格朗日插值

\(n+1\) 个点值确定一个 \(n\) 次多项式

\[f(x)=\sum_{i=1}^{n+1}y_{i}\prod_{j\ne i}\frac{x-x_{j}}{x_{i}-x_{j}} \]

数学分析

  • 泰勒展开

\[f(x)=\sum_{i=0}^{n}\frac{f^{(k)}(x_0)}{k!}(x-x_0)^k+R_n(x-x_0) \]

高等代数

抽象代数

  • Burnside 引理

有限群 \(G\) 作用在有限非空集合 \(X\) 上,\(\displaystyle|X/G|=\frac{1}{|G|}\sum_{x\in G}|X^x|\)

posted @ 2024-04-12 19:44  ft61  阅读(21)  评论(0)    收藏  举报