数论
1.求素数:
1>普通方法
2>素数筛选法
3>Mliier_Rabbin素数测试
费马小定理。若 ap-1 mod p = 1 ,则p有 3/4的概率是素数。
2.求an:
例如 a10=a5 * a5
a5 = a2 * a2 * a
a2 = a1 * a1
3.求最大公约数GCD:
1> gcd(A,B) = gcd(B,A mod B);
__int64 GCD(__int64 a,__int 64 b){
if(b == 0){
return a;
}
return GCD(b,a mod b);
}
4.求 d = gcd(a,b) = ax + by
且 |x| + |y| 最小,求x,y
gcd(a,b) = ax + by
gcd(b,a mod b) = bx' + (a - [a/b]向下取整 b)y'
= ay' + b(x' - [a/b]向下取整 y')
y' = x
x' = y + [a/b]向下取整 y'
x = y'
y = x' - [a/b]向下取整 y'
5.唯一素数分解
n = p1k1 p2k2 ... pmkm
6.欧拉函数:
与x互质切小于X的正整数个数
7.模线性方程 ax = b mod n
ax = ny + b
ax - ny = b
ax + by = d = gcd(a,b)
ax-ny = b
gcd(a,n) = d
若d能整除b
ax' + by' = d
ax - ny = b
推出 ax'(b/d) + ny'(b/a) = b
1> 有解 等价于 gcd(a,b)整除b
2> 有gcd(a,n)个数的解
3> x0 = x'(b/d)
xi = x0 + i * (n/d)