`{"id":"a3d131c8-d46a-4f86-9154-500aba838b73","name":"Gcd And Lcm","description":"<p>1. You are required to print the Greatest Common Divisor (GCD) of two numbers. </p><p>2. You are also required to print the Lowest Common Multiple (LCM) of the same numbers. </p><p>3. Take input \"num1\" and \"num2\" as the two numbers. </p><p>4. Print their GCD and LCM.</p>","inputFormat":"num1\r\nnum2\r\n.. the numbers whose GCD and LCM we have to find.","outputFormat":"a\r\nb\r\n.. where 'a' and 'b' are the GCD and LCM respectively.","constraints":"2 &lt;= n &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\nint main(int argc, char **argv){\r\n int num1, num2;\r\n cin >> num1 >> num2;\r\n\r\n //write your code here\r\n \r\n}"},"java":{"code":"import java.util.*;\r\n \r\n public class Main{\r\n \r\n public static void main(String[] args) {\r\n // write your code here \r\n }\r\n }"},"python":{"code":"def gcdandlcm(n1,n2):\n # write your code here\n\ndef main():\n n1 = int(input())\n n2 = int(input())\n gcdandlcm(n1,n2)\n\nif __name__==\"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"36\r\n24","sampleOutput":"12\r\n72","questionVideo":"https://www.youtube.com/embed/8RlrYFljNJI","hints":[],"associated":[{"id":"7d10285a-0e52-4c4a-843f-cb300650d53a","name":"What is the time complexity of GCD?","slug":"what-is-the-time-complexity-of-gcd","type":4},{"id":"9b24c8b6-d37f-4322-953a-777397c76d84","name":"How will n1 and n2 change in this question?","slug":"how-will-n1-and-n2-change-in-this-question","type":4},{"id":"b3727b16-1341-43fe-85d6-e9407cec5857","name":"What is the GCD and LCM of 24 and 36?","slug":"what-is-the-gcd-and-lcm-of-24-and-36","type":4},{"id":"daa0f06f-68a3-4039-84ce-ad3a311a7af7","name":"What is relation between GCD and LCM?","slug":"what-is-relation-between-gcd-and-lcm","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"72157774-7fd0-4b8e-88dc-037800acd626","name":"Getting Started","slug":"getting-started-9996","type":0},{"id":"2d16b228-f714-425c-a639-66e75ff8c958","name":"Gcd And Lcm","slug":"gcd-and-lcm","type":1}],"next":{"id":"2b40107a-a78c-4a0e-9a90-db3f529150bb","name":"Gcd And Lcm","type":3,"slug":"gcd-and-lcm"},"prev":{"id":"4f012c45-f101-4da4-91c8-c663b567bdca","name":"Rotate a Number","type":3,"slug":"rotate-a-number"}}}`

# Gcd And Lcm

<p>1. You are required to print the Greatest Common Divisor (GCD) of two numbers. </p><p>2. You are also required to print the Lowest Common Multiple (LCM) of the same numbers. </p><p>3. Take input "num1" and "num2" as the two numbers. </p><p>4. Print their GCD and LCM.</p>

`{"id":"a3d131c8-d46a-4f86-9154-500aba838b73","name":"Gcd And Lcm","description":"<p>1. You are required to print the Greatest Common Divisor (GCD) of two numbers. </p><p>2. You are also required to print the Lowest Common Multiple (LCM) of the same numbers. </p><p>3. Take input \"num1\" and \"num2\" as the two numbers. </p><p>4. Print their GCD and LCM.</p>","inputFormat":"num1\r\nnum2\r\n.. the numbers whose GCD and LCM we have to find.","outputFormat":"a\r\nb\r\n.. where 'a' and 'b' are the GCD and LCM respectively.","constraints":"2 &lt;= n &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\nint main(int argc, char **argv){\r\n int num1, num2;\r\n cin >> num1 >> num2;\r\n\r\n //write your code here\r\n \r\n}"},"java":{"code":"import java.util.*;\r\n \r\n public class Main{\r\n \r\n public static void main(String[] args) {\r\n // write your code here \r\n }\r\n }"},"python":{"code":"def gcdandlcm(n1,n2):\n # write your code here\n\ndef main():\n n1 = int(input())\n n2 = int(input())\n gcdandlcm(n1,n2)\n\nif __name__==\"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"36\r\n24","sampleOutput":"12\r\n72","questionVideo":"https://www.youtube.com/embed/8RlrYFljNJI","hints":[],"associated":[{"id":"7d10285a-0e52-4c4a-843f-cb300650d53a","name":"What is the time complexity of GCD?","slug":"what-is-the-time-complexity-of-gcd","type":4},{"id":"9b24c8b6-d37f-4322-953a-777397c76d84","name":"How will n1 and n2 change in this question?","slug":"how-will-n1-and-n2-change-in-this-question","type":4},{"id":"b3727b16-1341-43fe-85d6-e9407cec5857","name":"What is the GCD and LCM of 24 and 36?","slug":"what-is-the-gcd-and-lcm-of-24-and-36","type":4},{"id":"daa0f06f-68a3-4039-84ce-ad3a311a7af7","name":"What is relation between GCD and LCM?","slug":"what-is-relation-between-gcd-and-lcm","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"72157774-7fd0-4b8e-88dc-037800acd626","name":"Getting Started","slug":"getting-started-9996","type":0},{"id":"2d16b228-f714-425c-a639-66e75ff8c958","name":"Gcd And Lcm","slug":"gcd-and-lcm","type":1}],"next":{"id":"2b40107a-a78c-4a0e-9a90-db3f529150bb","name":"Gcd And Lcm","type":3,"slug":"gcd-and-lcm"},"prev":{"id":"4f012c45-f101-4da4-91c8-c663b567bdca","name":"Rotate a Number","type":3,"slug":"rotate-a-number"}}}`

Editor

# Gcd And Lcm

easy

1. You are required to print the Greatest Common Divisor (GCD) of two numbers.

2. You are also required to print the Lowest Common Multiple (LCM) of the same numbers.

3. Take input "num1" and "num2" as the two numbers.

4. Print their GCD and LCM.

2 <= n <= 10^9

## Format

### Input

num1 num2 .. the numbers whose GCD and LCM we have to find.

### Output

a b .. where 'a' and 'b' are the GCD and LCM respectively.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}36 24```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}12 72```

Question Video

Discussions

Show Discussion

Related Resources