Finding LCM using GCD is explained here but here the task is to find LCM without first calculating GCD.

**Examples:**

Input:7, 5Output:35Input:2, 6Output:6

The approach is to start with the largest of the 2 numbers and keep incrementing the larger number by itself till smaller number perfectly divides the resultant.

## C++

`// C++ program to find LCM of 2 numbers ` `// without using GCD ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return LCM of two numbers ` `int` `findLCM(` `int` `a, ` `int` `b) ` `{ ` ` ` `int` `lar = max(a, b); ` ` ` `int` `small = min(a, b); ` ` ` `for` `(` `int` `i = lar; ; i += lar) { ` ` ` `if` `(i % small == 0) ` ` ` `return` `i; ` ` ` `} ` `} ` ` ` `// Driver program to test above function ` `int` `main() ` `{ ` ` ` `int` `a = 5, b = 7; ` ` ` `cout << ` `"LCM of "` `<< a << ` `" and "` ` ` `<< b << ` `" is "` `<< findLCM(a, b); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find LCM of 2 numbers ` `// without using GCD ` `import` `java.io.*; ` `import` `java.lang.*; ` ` ` `class` `GfG { ` ` ` ` ` `// Function to return LCM of two numbers ` ` ` `public` `static` `int` `findLCM(` `int` `a, ` `int` `b) ` ` ` `{ ` ` ` `int` `lar = Math.max(a, b); ` ` ` `int` `small = Math.min(a, b); ` ` ` `for` `(` `int` `i = lar; ; i += lar) { ` ` ` `if` `(i % small == ` `0` `) ` ` ` `return` `i; ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver program to test above function ` ` ` `public` `static` `void` `main(String [] argc) ` ` ` `{ ` ` ` `int` `a = ` `5` `, b = ` `7` `; ` ` ` `System.out.println( ` `"LCM of "` `+ a + ` `" and "` ` ` `+ b + ` `" is "` `+ findLCM(a, b)); ` ` ` ` ` `} ` `} ` ` ` `// This dose is contributed by Sagar Shukla. ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 program to find ` `# LCM of 2 numbers without ` `# using GCD ` `import` `sys ` ` ` `# Function to return ` `# LCM of two numbers ` `def` `findLCM(a, b): ` ` ` ` ` `lar ` `=` `max` `(a, b) ` ` ` `small ` `=` `min` `(a, b) ` ` ` `i ` `=` `lar ` ` ` `while` `(` `1` `) : ` ` ` `if` `(i ` `%` `small ` `=` `=` `0` `): ` ` ` `return` `i ` ` ` `i ` `+` `=` `lar ` ` ` `# Driver Code ` `a ` `=` `5` `b ` `=` `7` `print` `(` `"LCM of "` `, a , ` `" and "` `, ` ` ` `b , ` `" is "` `, ` ` ` `findLCM(a, b), sep ` `=` `"") ` ` ` `# This code is contributed ` `# by Smitha ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find ` `// LCM of 2 numbers ` `// without using GCD ` `using` `System; ` ` ` `class` `GfG ` `{ ` ` ` ` ` `// Function to return ` ` ` `// LCM of two numbers ` ` ` `public` `static` `int` `findLCM(` `int` `a, ` ` ` `int` `b) ` ` ` `{ ` ` ` `int` `lar = Math.Max(a, b); ` ` ` `int` `small = Math.Min(a, b); ` ` ` `for` `(` `int` `i = lar; ; i += lar) ` ` ` `{ ` ` ` `if` `(i % small == 0) ` ` ` `return` `i; ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `a = 5, b = 7; ` ` ` `Console.WriteLine(` `"LCM of "` `+ a + ` ` ` `" and "` `+ b + ` ` ` `" is "` `+ ` ` ` `findLCM(a, b)); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by anuj_67. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find ` `// LCM of 2 numbers ` `// without using GCD ` ` ` `// Function to return ` `// LCM of two numbers ` `function` `findLCM(` `$a` `, ` `$b` `) ` `{ ` ` ` `$lar` `= max(` `$a` `, ` `$b` `); ` ` ` `$small` `= min(` `$a` `, ` `$b` `); ` ` ` `for` `(` `$i` `= ` `$lar` `; ; ` `$i` `+= ` `$lar` `) ` ` ` `{ ` ` ` `if` `(` `$i` `% ` `$small` `== 0) ` ` ` `return` `$i` `; ` ` ` `} ` `} ` ` ` `// Driver Code ` `$a` `= 5; ` `$b` `= 7; ` `echo` `"LCM of "` `, ` `$a` `, ` `" and "` `, ` ` ` `$b` `, ` `" is "` `, ` ` ` `findLCM(` `$a` `, ` `$b` `); ` ` ` `// This code is contributed ` `// by Smitha ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

LCM of 5 and 7 is 35

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Sum of LCM(1, n), LCM(2, n), LCM(3, n), ... , LCM(n, n)
- Finding LCM of more than two (or array) numbers without using GCD
- Given GCD G and LCM L, find number of possible pairs (a, b)
- Find any pair with given GCD and LCM
- Find the GCD of LCM of all unique pairs in an Array
- Find the ratio of LCM to GCD of a given Array
- Minimum replacement of pairs by their LCM required to reduce given array to its LCM
- GCD, LCM and Distributive Property
- Levelwise Alternating GCD and LCM of nodes in Segment Tree
- Minimum LCM and GCD possible among all possible sub-arrays
- Print any pair of integers with sum of GCD and LCM equals to N
- Count of all possible pairs having sum of LCM and GCD equal to N
- Program to find GCD or HCF of two numbers using Middle School Procedure
- Program to find LCM of two numbers
- Program to find LCM of two Fibonnaci Numbers
- Program to find the LCM of two prime numbers
- Pair of integers having least GCD among all given pairs having GCD exceeding K
- Program to find GCD of floating point numbers
- Program to find GCD or HCF of two numbers
- Maximum sum of distinct numbers such that LCM of these numbers is N

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.