Dcoder icon

Let's get GCD @ Dcoder

By Lochard | As a newbie programmer | 1 Jul 2023


Problem: Cody was doing his maths homework, suddenly he found a GCD(Greatest Comman divisor) problem. He is very lazy to do all the calculations for this exercise, so he just took his mobile and opened the Dcoder App, decided to code a program to find solution to GCD problem. You have to help him making this program, where you are presented with 2 integers, and you have to find their Greatest Comman Divisor.

The HCF or GCD of two integers is the largest integer that can exactly divide both numbers (without a remainder).

Input: Input contains 2 integers n1 and n2 separated by a newline.

Output: Print the GCD of n1 and n2

Constraints: 1≤n1,n2≤1000

Sample Input: 54

24

Sample Output: 

6

from math import gcd
print(gcd(int(input()), int(input())))

How do you rate this article?

0


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.