Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c4c5e5

Browse filesBrowse files
CO18326abranhe
authored andcommitted
Create common_divisor_count.py
1 parent e43b6bf commit 9c4c5e5
Copy full SHA for 9c4c5e5

File tree

Expand file treeCollapse file tree

1 file changed

+31
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+31
-0
lines changed

‎math/common_divisor_count.py

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
3+
4+
'''
5+
6+
The function takes two integers as input and return the number of common divisors of
7+
that pair
8+
9+
10+
11+
'''
12+
def cd_count(a,b):
13+
14+
if a==0 or b==0:
15+
return 2
16+
a=(-1*a if a<0 else a)
17+
b=(-1*b if b<0 else b)
18+
19+
result=0
20+
while a!=0:
21+
c=a
22+
a=b%a
23+
b=c
24+
25+
for i in range(1,int((b**0.5)+1)):
26+
if b%i==0:
27+
if b/i==i:
28+
result=result+1
29+
else:
30+
result=result+2
31+
return result

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.