# Find GCD of two numbers

Hello,

## What is GCD?

GCD(Greatest common divisor) or HCF(Highest common factor) is common factor between 2 or more numbers which is divisible by both.

GCD of 4 and 6 is 2. Here both 4 and 6 have common factor 2.

GCD of 10,25,40 is 5

### How to calculate GCD between 2 numbers?

To find our GCD between 2 numbers, you need to take factors of both numbers, and see the common factors. GCD is product of common factors.

For example : To calculate GCD of 4 and 6

Factor of 4 = 1,2,4

Factor of 6 = 1,2,3,6

Common factors= 1,2

GCD=2

### How to find GCD between 2 number in Python

``````def getFactor(number):
factors = []
i=1
while(i<number+1):
if(number%i==0):
factors.append(i)
i+=1
return factors

def getCommon(a,b):
c = [value for value in a if value in b]
c.sort()
c.reverse()
return c

def getGCD(num1,num2):
if(num1==num2):
return num1

if(num1%num2==0):
return num2

if(num2%num1==0):
return num1

factor_num1 = getFactor(num1)
factor_num2 = getFactor(num2)
return getCommon(factor_num1,factor_num2)

print(getGCD(320,400))``````

## End note

In the article, you have seen how to find GCD between 2 or more number in Python.

If in case you have doubt regarding implementation, please feel free to share us your concerns in discussion thread below, or mail us to info@xamnation.com
{"ft_lang_label":"__label__en","ft_lang_prob":0.8551027,"math_prob":0.9930266,"size":2036,"snap":"2022-40-2023-06","text_gpt3_token_len":541,"char_repetition_ratio":0.1382874,"word_repetition_ratio":0.027607363,"special_character_ratio":0.2549116,"punctuation_ratio":0.11764706,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99921423,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-05T08:21:35Z\",\"WARC-Record-ID\":\"<urn:uuid:1f717ccc-a548-4b1f-ad73-6d5f40d0e3ab>\",\"Content-Length\":\"134825\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f7ab60ca-39a1-4f73-8c99-3dd9aeed4933>\",\"WARC-Concurrent-To\":\"<urn:uuid:79b4b4ec-5a74-4f0e-90de-a396fe02ac45>\",\"WARC-IP-Address\":\"198.54.115.202\",\"WARC-Target-URI\":\"https://www.xamnation.com/find-gcd-of-two-numbers/\",\"WARC-Payload-Digest\":\"sha1:P2MMSLBNOTU6A7ZCBWQIOPLQWJQBJTTJ\",\"WARC-Block-Digest\":\"sha1:CF3VQEOHUBRJJDBILB6BFL22RAILU5T2\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764500250.51_warc_CC-MAIN-20230205063441-20230205093441-00299.warc.gz\"}"}