acm比賽常用模板
阿新 • • 發佈:2018-12-14
亂七八糟模板
- 標頭檔案,巨集定義,讀入掛
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 結構體過載運算子
- 1
- 2
- 3
- 4
資料結構
- 樹狀陣列
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
數論模板
- 快速冪
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 矩陣快速冪
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 素數的兩種篩法
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 尤拉函式
在數論,對正整數n,尤拉函式是小於n的正整數中與n互質的數的數目(φ(1)=1)。
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 歐幾里得GCD,擴充套件~
歐幾里德演算法又稱輾轉相除法,用於計算兩個整數a,b的最大公約數(greatest common divisor)。
擴充套件歐幾里德演算法是用來在已知a, b求解一組x,y,使它們滿足貝祖等式: ax+by = gcd(a, b) =d(解一定存在,根據數論中的相關定理)。擴充套件歐幾里德常用在求解模線性方程及方程組中。
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 逆元
方程ax≡1(mod p),的解稱為a關於模p的逆,當gcd(a,p)==1(即a,p互質)時,方程有唯一解,否則無解。
對於一些題目會要求把結果MOD一個數,通常是一個較大的質數,對於加減乘法通過同餘定理可以直接拆開計算,但對於(a/b)%MOD這個式子,是不可以寫成(a%MOD/b%MOD)%MOD的,但是可以寫為(a*b^-1)%MOD,其中b^-1表示b的逆元。
- 1
- 2
- 3
- 4
- 5
- 中國剩餘定理(CRT) ,擴充套件~
中國剩餘定理給出了以下的一元線性同餘方程組:
假設整數m1,m2, ... ,mn兩兩互質,則對任意的整數:a1,a2, ... ,an,方程組 有解,即x,擴充套件剩餘定理就是m1,m2···mn,這幾個數不兩兩互質的情況
- 1