Skip to content

Instantly share code, notes, and snippets.

View Francis-Lee-Earth's full-sized avatar

Francis, Lee Francis-Lee-Earth

  • Earth
View GitHub Profile
@Francis-Lee-Earth
Francis-Lee-Earth / ModularMultiplicativeInverse.py
Last active October 11, 2018 12:50
Modular Multiplicative Inverse
def greatest_common_divisor_extended(a, b):
'''
擴展歐幾里得算法 (Extended Euclidean algorithm)
'''
if b == 0:
return a, 1, 0
gcd, y, x = greatest_common_divisor_extended(b, a % b)
return gcd, x, y - (a // b) * x
@Francis-Lee-Earth
Francis-Lee-Earth / GreatestCommonDivisor.py
Last active October 11, 2018 12:48
Greatest Common Divisor (GCD)
def greatest_common_divisor(a, b):
"""
除非 b == 0,否則結果將與 b 具有相同的正負號
(因此,當 b 除以它,結果是正號)
"""
while b > 0:
a, b = b, a % b
return a
import numpy as np
a = np.array([
[1, -2, -1],
[2, -1, 1],
[3, -6, -5]
])
a_inv = np.linalg.inv(a)
print("A:")
import numpy as np
a = np.array([
[5, 12],
[15, 25]
])
b = np.array(
[20, 10]
)