Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/E869120/math-algorithm-book
/ modpow
Function
modpow
codes/python/Code_4_06_4.py:2–9 ·
view source on GitHub ↗
(a, b, m)
Source
from the content-addressed store, hash-verified
1
# 繰り返し二乗法(p は a**1, a**2, a**4, a**8, ... といった値をとる)
2
def
modpow(a, b, m):
3
p = a
4
answer = 1
5
for
i in range(30):
6
if
(b & (1 << i)) != 0:
7
answer = (answer * p) % m
8
p = (p * p) % m
9
return
answer
10
11
MOD = 1000000007
12
Callers
1
Code_4_06_4.py
File · 0.70
Calls
no outgoing calls
Tested by
no test coverage detected