ตัวประกอบร่วมสูงสุดหรือตัวหารร่วมที่ยิ่งใหญ่ที่สุดของจำนวนเต็มตั้งแต่สองตัวขึ้นไปคือจำนวนเต็มบวกที่ใหญ่ที่สุดที่หารตัวเลขเท่าๆ กันโดยไม่มีเศษเหลือ ตัวอย่างเช่น GCD ของ 8 และ 12 คือ 4
x = int(input("Enter first number: "))
y = int(input("Enter second number: "))
if x > y:
smaller = y
else:
smaller = x
for i in range(1,smaller + 1):
if((x % i == 0) and (y % i == 0)):
hcf = i
print("The H.C.F. of", x,"and", x,"is", hcf)