MCPcopy Create free account
hub / github.com/E869120/math-algorithm-book / power

Function power

codes/python/Code_4_07_1.py:17–29  ·  view source on GitHub ↗
(A, n)

Source from the content-addressed store, hash-verified

15
16# A の n 乗を返す関数
17def power(A, n):
18 P = deepcopy(A)
19 Q = [ [ 0, 0 ], [ 0, 0 ] ]
20 flag = False
21 for i in range(60):
22 if (n & (1 << i)) != 0:
23 if flag == False:
24 Q = deepcopy(P)
25 flag = True
26 else:
27 Q = deepcopy(multiply(Q, P))
28 P = deepcopy(multiply(P, P))
29 return Q
30
31# 入力 → 累乗の計算(N が 2 以上でなければ正しく動作しないので注意)
32N = int(input())

Callers 1

Code_4_07_1.pyFile · 0.70

Calls 1

multiplyFunction · 0.70

Tested by

no test coverage detected