MeetCode
GCD Of Two Numbers
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Run
Submit
Dark
Problem Statement
Solutions
Submissions
GCD Of Two Numbers
Easy
Computer Mathematics
GCD/LCM & Euclid
26 views
Explanation
Complexity
Problem Statement
Compute gcd(a,b).
Input Format
Two integers a b.
Output Format
One integer gcd.
Example
Input
18 48
Output
6
Constraints
|a|,|b|
Input / Output Format
Input Format
Two integers a b.
Output Format
One integer gcd.
Constraints
|a|,|b|
Examples
Input:
18 48
Output:
6
Example Solution (Public)
Computer Mathematics
Use Euclid: while b!=0 set (a,b)=(b,a%b). Answer is abs(a).
Official Solution Code
Wrap
Copy
Use Euclid: while b!=0 set (a,b)=(b,a%b). Answer is abs(a).
Please
login
to submit solutions.
Editor
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Test Cases
Output
Submission Result
Input
18 48
Expected Output
6
Compile Output
Error
Output
Please
login
to submit solutions.