LCM of two large numbers | Java Program to find LCM of two large numbers ; function to calculate LCM of two large numbers ; convert string ' a ' and ' b ' into BigInteger ; calculate multiplication of two bigintegers ; calculate gcd of two bigintegers ; calculate lcm using formula : lcm * gcd = x * y ; Driver Code ; Input ' a ' and ' b ' are in the form of strings because they can not be handled by integer data type
import java . math . * ; import java . lang . * ; import java . util . * ; public class GFG { public static BigInteger lcm ( String a , String b ) { BigInteger s = new BigInteger ( a ) ; BigInteger s1 = new BigInteger ( b ) ; BigInteger mul = s . multiply ( s1 ) ; BigInteger gcd = s . gcd ( s1 ) ; BigInteger lcm = mul . divide ( gcd ) ; return lcm ; } public static void main ( String [ ] args ) { String a = "36594652830916364940473625749407" ; String b = "448507083624364748494746353648484939" ; System . out . print ( lcm ( a , b ) ) ; } }