Skip to content

Commit d72f145

Browse files
committed
添加大数乘法取模模板
1 parent 12d871a commit d72f145

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

math/数论算法模板总结.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void find_factor(LL n,std::map<LL, int> & m){
144144
$\phi(n) = n\prod_{i = 1}^{k}(1-\frac{1}{p_i})$
145145
证明详见《初等数论及其应用》
146146
147-
```
147+
```c++
148148
int euler_phi(int n)
149149
{
150150
int ans = n;
@@ -160,7 +160,7 @@ int euler_phi(int n)
160160
```
161161
phi_table,类似于线性筛的做法
162162

163-
```
163+
```c++
164164
void phi_table(int n)
165165
{
166166
memset(phi,0,sizeof(phi[0])*(n+5));
@@ -182,7 +182,7 @@ void phi_table(int n)
182182
#模运算
183183
##power_mod
184184
185-
```
185+
```c++
186186
LL power_mod(LL x,LL n,LL mod)
187187
{
188188
LL res = 1;
@@ -196,9 +196,24 @@ LL power_mod(LL x,LL n,LL mod)
196196
}
197197
198198
```
199+
##大数乘法取模
199200

200-
##大整数取模
201+
```c++
202+
LL mulmod(LL a,LL b,LL mod){
203+
LL res =0,y = a%mod;
204+
while (b) {
205+
if(b&1)res = (res+y)%mod;
206+
b>>=1;
207+
y = (y<<1)%mod;
208+
}
209+
return res;
210+
}
201211
```
212+
213+
214+
##大整数取模
215+
216+
```c++
202217
LL big_mod(string val,LL mod)
203218
{
204219
LL res = 0;

0 commit comments

Comments
 (0)