Skip to content

Commit ba08647

Browse files
author
shengshijun
committed
用欧几里得算法求解最大公约数
1 parent 510b054 commit ba08647

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ algorithm
3939
###斐波那契树
4040
1. 使用循环实现的算法o(n)
4141

42+
##数论算法
43+
1. 欧几里得算法求解最大公约数
44+
4245

4346
#数据结构
4447
------------

number_theory/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python
2+
# -*- coding:UTF-8
3+
__author__ = 'shenshijun'

number_theory/gcd.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
# -*- coding:UTF-8
3+
__author__ = 'shenshijun'
4+
5+
6+
def gcd(a, b):
7+
divisor = a
8+
dividend = b
9+
while dividend is not 0:
10+
divisor, dividend = dividend, divisor % dividend
11+
return divisor
12+
13+
14+
def main():
15+
print(gcd(12, 18))
16+
17+
18+
if __name__ == "__main__":
19+
main()
20+

0 commit comments

Comments
 (0)