mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
Improved Formatting and Style of Math Algos (#960)
* Improved Formatting and Style I improved formatting and style to make PyLama happier. Linters used: - mccabe - pep257 - pydocstyle - pep8 - pycodestyle - pyflakes - pylint - isort * Create volume.py This script calculates the volumes of various shapes. * Delete lucasSeries.py * Revert "Delete lucasSeries.py" This reverts commit 64c19f7a6c8b74e15bed07f0f0337598a001ceb4. * Update lucasSeries.py
This commit is contained in:
@ -1,20 +1,38 @@
|
||||
"""
|
||||
Extended Euclidean Algorithm.
|
||||
|
||||
Finds 2 numbers a and b such that it satisfies
|
||||
the equation am + bn = gcd(m, n) (a.k.a Bezout's Identity)
|
||||
"""
|
||||
|
||||
# @Author: S. Sharma <silentcat>
|
||||
# @Date: 2019-02-25T12:08:53-06:00
|
||||
# @Email: silentcat@protonmail.com
|
||||
# @Last modified by: silentcat
|
||||
# @Last modified time: 2019-02-26T07:07:38-06:00
|
||||
# @Last modified by: PatOnTheBack
|
||||
# @Last modified time: 2019-07-05
|
||||
|
||||
import sys
|
||||
|
||||
# Finds 2 numbers a and b such that it satisfies
|
||||
# the equation am + bn = gcd(m, n) (a.k.a Bezout's Identity)
|
||||
|
||||
def extended_euclidean_algorithm(m, n):
|
||||
a = 0; aprime = 1; b = 1; bprime = 0
|
||||
q = 0; r = 0
|
||||
"""
|
||||
Extended Euclidean Algorithm.
|
||||
|
||||
Finds 2 numbers a and b such that it satisfies
|
||||
the equation am + bn = gcd(m, n) (a.k.a Bezout's Identity)
|
||||
"""
|
||||
a = 0
|
||||
a_prime = 1
|
||||
b = 1
|
||||
b_prime = 0
|
||||
q = 0
|
||||
r = 0
|
||||
if m > n:
|
||||
c = m; d = n
|
||||
c = m
|
||||
d = n
|
||||
else:
|
||||
c = n; d = m
|
||||
c = n
|
||||
d = m
|
||||
|
||||
while True:
|
||||
q = int(c / d)
|
||||
@ -24,22 +42,24 @@ def extended_euclidean_algorithm(m, n):
|
||||
c = d
|
||||
d = r
|
||||
|
||||
t = aprime
|
||||
aprime = a
|
||||
a = t - q*a
|
||||
t = a_prime
|
||||
a_prime = a
|
||||
a = t - q * a
|
||||
|
||||
t = bprime
|
||||
bprime = b
|
||||
b = t - q*b
|
||||
t = b_prime
|
||||
b_prime = b
|
||||
b = t - q * b
|
||||
|
||||
pair = None
|
||||
if m > n:
|
||||
pair = (a,b)
|
||||
pair = (a, b)
|
||||
else:
|
||||
pair = (b,a)
|
||||
pair = (b, a)
|
||||
return pair
|
||||
|
||||
|
||||
def main():
|
||||
"""Call Extended Euclidean Algorithm."""
|
||||
if len(sys.argv) < 3:
|
||||
print('2 integer arguments required')
|
||||
exit(1)
|
||||
@ -47,5 +67,6 @@ def main():
|
||||
n = int(sys.argv[2])
|
||||
print(extended_euclidean_algorithm(m, n))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user