Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

find lcm with gcd

import java.util.*;

public class LCM {
  
  public static long lcm(int a, int b) {

    long x = (a/euclidGcd(a, b));

    return x * b;

  }

  public static int euclidGcd(int a, int b) {

    if (b == 0)
      return a;

    int aprime = a%b;
    
    return euclidGcd(b, aprime);
  }
  
  public static void main(String args[]) {
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    int b = scanner.nextInt();

    System.out.println(lcm(a, b));
  }
}
 
PREVIOUS NEXT
Tagged: #find #lcm #gcd
ADD COMMENT
Topic
Name
7+3 =