diff --git a/math/number_theory/Lcm.java b/math/number_theory/Lcm.java new file mode 100644 index 0000000..da1670c --- /dev/null +++ b/math/number_theory/Lcm.java @@ -0,0 +1,19 @@ +import java.io.*; +import java.util.*; + +class Lcm{ + static int gcd(int x, int y){ + if (x == 0) return y; + return gcd(y % x, x); + } + + static int lcm(int x, int y){ + return (x / gcd(x, y)) * y; + } + + public static void main(String[] args){ + int x = 15, y = 20; + System.out.println("LCM of " + x + " and " + y + " is " + lcm(x, y)); + } +} +